Created
November 30, 2018 13:23
-
-
Save swashata/659e9f9e22ea2fb066ada17a7b385938 to your computer and use it in GitHub Desktop.
Array Reduce
This file contains hidden or 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 arr = [1, 2, 3, 4, 5]; | |
// Without initial value | |
const sumOfArr = arr.reduce((acc, cur) => { | |
return acc + cur; | |
}); | |
console.log(sumOfArr); | |
// With initial value | |
const sumWithInitialValue = arr.reduce((acc, cur) => { | |
return acc + cur; | |
}, 999); // 999 passed as second parameter of arr.reduce function | |
console.log(sumWithInitialValue); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment