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.
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.
That was my question indeed if it actually is only 1 iteration.
Very cool stuff actually