how
reduce
works in
JS
?
const initValue =
0
const values = [
3
,
5
,
1
,
4
,
2
]
const total = values.reduce((
acc
,
item
) => {
return
acc
+
item
}, initValue)
view source code on github