re: Everything You Need to Know About Array#reduce VIEW POST


Nice summary, thanks for writing it up. "Reduce" is an important concept in many contexts, so if you understand it once, the others will be a lot easier.

I think there's an error in one of the code snippets, where you use this line:

accumulator = reducer(accumulator, this[i], i, array);

I think instead it should be:

accumulator = reducer(accumulator, this[i], i, this);

Because at that point there is no array variable.


Hi Peter! Thanks for pointing out my mistake! I'll fix it tonight. And yes I agree completely. Reduce is a very important function!

Code of Conduct Report abuse