Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reduce example - sum
const numbers = [2,10,11,5,16];
var sum = numbers.reduce(function (acc, currValue) {
return acc + currValue;
}, 0);
// ES6
const sum = numbers.reduce((acc, currValue) => {
return acc + currValue;
}, 0);
console.log(sum); // 44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.