Last active
August 8, 2016 22:31
-
-
Save peterbsmyth/432330294b18091c7e55b6caf8f5535f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function takesACallBack(something, callback) { | |
callback(something); | |
} | |
function logger(argument) { | |
console.log(argument); | |
} | |
logger("hello world"); | |
takesACallBack("hello world", function(arg) { | |
console.log(arg); | |
}); | |
// performsMath takes in a Number for a and b | |
// take a callback function for callback | |
// the callback functions arguments are two numbers | |
// Function to perform math on each passed in argument | |
// Invoked with arguments (firstNumber, secondNumber). Return result of mathematical function | |
function performsMath(a, b, callback) { | |
if(typeof callback !== 'function') { | |
throw Error("callback must be a function") | |
} | |
console.log(callback(a, b)); | |
} | |
function add(first, second) { | |
return first + second; | |
} | |
function divide(first, second) { | |
return first / second; | |
} | |
function subtract(first, second) { | |
return first - second; | |
} | |
function multiply(first, second) { | |
return first * second; | |
} | |
performsMath(5,2, multiply); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment