- How to early break reduce () method? - Stack Overflow
A couple of comments that "this doesn't do what reduce does", which is true, but it can Here's an example of using every in a similar manner to reduce that returns as soon as the break condition is reached
- How to use array reduce with condition in JavaScript?
reduce goes through each item and expects a return value If you don't return a value, it will be undefined So after the third iteration, the sum will be undefined
- Python: reduce (list of strings) - gt; string - Stack Overflow
Note: I won't prefer this way, but for the sake of completeness, you can do it with reduce, like this data = ['alfa', 'bravo', 'charlie', 'delta'] print(ft reduce(lambda x, y: x + (" " if x else "") + y[0], data, "")) # a b c d Now, the last empty string will be the first value for x in the first iteration
|