DEV Community

loading...

Discussion on: Better loops in JavaScript

Collapse
summerkiflain profile image
Summer Kiflain

Nice article.

//sum of array elements
arr.reduce((accumulator, currentValue) => (acc += curr), 0)

should be:

//sum of array elements
arr.reduce((accumulator, currentValue) => (accumulator += currentValue), 0)

Collapse
kartik2406 profile image
Kartik Malik Author

Changed it. Thank you :)