Skip to content

Instantly share code, notes, and snippets.

@gitfaf
Created August 17, 2017 21:21
Show Gist options
  • Save gitfaf/10b8099a2a73b973b767382d545e21c8 to your computer and use it in GitHub Desktop.
Save gitfaf/10b8099a2a73b973b767382d545e21c8 to your computer and use it in GitHub Desktop.
Eloquent JS - Higher Order Function snippet.
function forEach (array, action) {
for(let i = 0, length = array.length; i < length; i++) {
action(array[i]);
}
}
function sumOf(array) {
let sum = 0;
forEach(array, value => sum += value);
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment