Skip to content

Instantly share code, notes, and snippets.

@koyacode
Created January 24, 2020 13:02
Show Gist options
  • Save koyacode/04b16aa2886c4275746a74e959fc7845 to your computer and use it in GitHub Desktop.
Save koyacode/04b16aa2886c4275746a74e959fc7845 to your computer and use it in GitHub Desktop.
function myFunction() {
const array1 = [1, 2, 3, 4];
// const reducer = (accumulator, currentValue) => accumulator + currentValue;
const reducer = function(accumulator, currentValue) { return accumulator + currentValue;};
// 1 + 2 + 3 + 4
console.log(array1.reduce(reducer));
// expected output: 10
// 5 + 1 + 2 + 3 + 4
console.log(array1.reduce(reducer, 5));
// expected output: 15
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment