Understanding the Almighty Reducer

I was reently mentoring someone who had trouble with the .reduce() method in JavaScript. Namely, how you get from this:
const nums = [1, 2, 3]
let value = 0
for (let i = 0; i < nums.length; i++) { value += nums[i] } ...to this: const nums = [1, 2, 3] const value = nums.reduce((ac, next) => ac + next, 0)
They are functionally equivalent and they both sum up all the numbers in the array, but there is …
The post Understanding the Almighty Reducer appeared first on CSS-Tricks.

Link: https://css-tricks.com/understanding-the-almighty-reducer/