Reduce until run in Javascript

After ES6, we tend to use map, filter a lot. And sometimes if we really need to get hands dirty, we can use reduce where we take an initial state and reduce it to next state going through all elements.

Looping through the entire array can be a bit expensive, especially when you want to stop when certain condition is met. This conditional reduce can be implemented using a Lazy library, where each element…