reduce exmaple js code example
Example 1: js reduce
Sum array elements:
let myArr = [1,2,3,-1,-34,0]
return myArr.reduce((a,b) => a + b,0)
Example 2: syntax of reduce in js
[1,2,3,4,5].reduce((acc, current)=>acc+current, 0)
Sum array elements:
let myArr = [1,2,3,-1,-34,0]
return myArr.reduce((a,b) => a + b,0)
[1,2,3,4,5].reduce((acc, current)=>acc+current, 0)