-
Notifications
You must be signed in to change notification settings - Fork 188
Closed
Description
Taking a cumulative sum is a common function in numeric computing and I've found myself repeatedly reaching for it over the years.
[1, 2, 3, 4].reduce((a, b) => (a.push(b + (a.length ? a[a.length-1] : 0)), a), [])
It can be implemented in one line, though you can achieve better performance by copying the array and running through 1:n
adding a[n-1]
to a[n]
inside each iteration.
xavierguihot
Metadata
Metadata
Assignees
Labels
No labels