Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mjapanwala/e78f920934b05b741252b43afd6b5c97 to your computer and use it in GitHub Desktop.
Save mjapanwala/e78f920934b05b741252b43afd6b5c97 to your computer and use it in GitHub Desktop.
How to use reduce() method
const sum = [5, 1, 4, 8]
const reduceFunction = sum.reduce(function(accumulator, currentValue) {
return accumulator + currentValue
},0)
accumulator is either the initial value to begin with which is the second argument, or the total of the iteration, the last iteration will be the result.
current value will be each element.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment