Map ⇄ Filter ⇄ Reduce

added by JavaScript Kicks
12/16/2019 10:27:37 AM

354 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