Last active
February 11, 2019 14:38
-
-
Save ajyounguk/fe8532727a72c575dfb8e5e0eed2ab9f to your computer and use it in GitHub Desktop.
node js function notation and syntactic sugar
This file contains 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
// from https://medium.com/@chineketobenna/lambda-expressions-vs-anonymous-functions-in-javascript-3aa760c958ae | |
function traverseArray(arr, func) { | |
let result = ''; | |
for (const value of arr) { | |
result += func(value) + ' '; | |
} | |
console.log(result); | |
} | |
const arr = [1, 2, 3, 4, 5]; | |
const doubler = value => value * 2; | |
////alternatively, can be written verbosely as | |
// const doubler = (value) => { | |
// return value * 2; | |
//} | |
// or link this: | |
// const doubler = function(value) { | |
// return value * 2 | |
//} | |
traverseArray(arr, doubler); | |
//result: 2 4 6 8 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment