DEV Community

Discussion on: JavaScript reduce() method

Collapse
 
dailydevtips1 profile image
Chris Bongers

Oh wow, actually wasn't aware of that, thanks for bringing that to the attention!
So when you say it's 1 iteration, does that mean even underwater it doesn't loop?

Just wondering from a user performance part of the view, if the reduce is quicker than the filter.map combi?

I would suspect so.

Collapse
 
lexlohr profile image
Alex Lohr

I don't really get that "underwater" question. It is only iterating over the array once, whereas the filter/map variant will iterate once to create a filtered representation of the array and once more to map it.

And yes, the reduce will be somewhat faster, even though the native array methods are pretty optimized already.

Thread Thread
 
dailydevtips1 profile image
Chris Bongers

That was my question indeed if it actually is only 1 iteration.
Very cool stuff actually