DEV Community

Discussion on: What s wrong with Array.reduce ?

Collapse
 
functional_js profile image
Functional Javascript

Good work Davide.

a.
Let me mention that to keep the use of reduce on it's semantic intention, pass in a list of elements of type T then return a single value that is of type T.

b.
I prefer a loop over a reduce simply for performance reasons.

In my performance tests, a loop will run about 10% faster on small arrays, but precipitously faster as array size increases; In the thousands or millions, a loop will process 5 to 15 TIMES faster than reduce.

Resource

I've written an article on a criteria set one should consider when deciding over a choice of implementations to use.
tltr: should always choose the fastest implementation when robustness and security are equal....
dev.to/functional_js/squeezing-out...

Collapse
 
dvddpl profile image
Davide de Paolis

point A is very interesting. i like it. and it makes perfectly sense. and reduces the use cases for reduce :-)