Created
June 24, 2018 17:57
-
-
Save sevperez/c7c30fc617c3e4f62d70c1cde6e1d684 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
var myNums = [1, 2, 3, 4, 5]; | |
function doubleNum(num) { | |
return num * 2; | |
} | |
// Built-in Array.prototype.map function, using anonymous function argument | |
var doubledNums = myNums.map(function(num) { | |
return num * 2; | |
}); | |
console.log(doubledNums); // logs "[2, 4, 6, 8, 10]" | |
// Built-in Array.prototype.map function, using named callback argument | |
var otherDoubledNums = myNums.map(doubleNum); | |
console.log(otherDoubledNums); // logs "[2, 4, 6, 8, 10]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment