DEV Community

Discussion on: JavaScript Array Reduce Doesn't Like Objects

Collapse
 
kosich profile image
Kostia Palchyk

Maybe, the (a, b) => ... notation was confusing — it kinda implies that a and b are array values, while actually a is the accumulator and b is the current value.

So nowadays I define reduce fn params as acc and curr:

[ /**/ ].reduce((acc, curr) => acc + curr.data, 0)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
rfornal profile image
bob.ts

Excellent thought. I'll adjust my code this way in the future!

Collapse
 
jimmymcbride profile image
Jimmy McBride

I think I just said what this guy pointed out already. Haha