2 ms·
A fold is usually restricted to a combining function of 2 arguments - accumulated-so-far and current item. A for-loop's body has no such restrictions, it can a
by JBiserkov 9y ago
A fold is usually restricted to a combining function of 2 arguments - accumulated-so-far and current item.
A for-loop's body has no such restrictions, it can access any number of neighbor elements if the algorithm so requires.
a[i] = a[i-1] * a[i+1]
- rjeli 9y agoA for loop is a fold over the local context and the index