Skip to content

Instantly share code, notes, and snippets.

@ajyounguk
Last active February 11, 2019 14:38
Show Gist options
  • Save ajyounguk/fe8532727a72c575dfb8e5e0eed2ab9f to your computer and use it in GitHub Desktop.
Save ajyounguk/fe8532727a72c575dfb8e5e0eed2ab9f to your computer and use it in GitHub Desktop.
node js function notation and syntactic sugar
// 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