Map⇄Filter⇄Reduce↻

added by JavaScript Kicks
10/14/2019 9:28:14 AM

387 Views

const arr = [3, 4, 2, 9];const reduce=(accumulator, currentValue)=>accumulator+currentValue;console.log(arr.reduce(reduce));console.log(arr.reduce(reduce, 7)); In the above code, we create a reduce function which will be passed as a callback to the .reduce() function. The function returns the addition of all the elements in the array.


0 comments