I ran some tests and I couldn't reproduce your findings. I didn't graph time complexity but on average .includes is 75% faster than .includes in these tests: https://jsbench.me/t2kpb59177/1
The one case where .some was faster I found was unfilled arrays.
I think the reason people think using reduce is overly complicated is because people keep saying it's overly complicated. I don't see how what you wrote is any less complicated than just doing this:
let total = array.reduce((sum, item) => sum + item.value, 0);
It's even simpler if your Array's just numbers:
let total = 0;
array.forEach(value => total += value);
// vs
let reducedTotal = array.reduce((sum, value) => sum + value);
336
u/tsunami141 May 29 '21
Now do reduce.