Implement prefix sum, with an optional argument being the commutative sum function.
For example, the prefix sum of [1, 2, 3, 4] is [1, 1+2, 1+2+3, 1+2+3+4] or [1, 3, 6, 10], but with the multiplication operator as its sum function, it's [1, 1*2, 1*2*3, 1*2*3*4] or [1, 2, 6, 24].
prefixSum
Where to implement
src/prefixSum.js
Description (optional)
Implement prefix sum, with an optional argument being the commutative sum function. For example, the prefix sum of
[1, 2, 3, 4]
is[1, 1+2, 1+2+3, 1+2+3+4]
or[1, 3, 6, 10]
, but with the multiplication operator as its sum function, it's[1, 1*2, 1*2*3, 1*2*3*4]
or[1, 2, 6, 24]
.