Created
February 14, 2018 14:38
-
-
Save JoaoCnh/f10fb489b10575a9896bd61b1996a0f3 to your computer and use it in GitHub Desktop.
Reduce example - sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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