Created
July 22, 2023 05:40
-
-
Save mjapanwala/e78f920934b05b741252b43afd6b5c97 to your computer and use it in GitHub Desktop.
How to use reduce() method
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 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