Skip to content

Instantly share code, notes, and snippets.

@JoaoCnh
Created February 14, 2018 14:38
Show Gist options
  • Save JoaoCnh/f10fb489b10575a9896bd61b1996a0f3 to your computer and use it in GitHub Desktop.
Save JoaoCnh/f10fb489b10575a9896bd61b1996a0f3 to your computer and use it in GitHub Desktop.
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