cumulativeSum method
Returns the running cumulative sum of a List<num>.
[1, 2, 3, 4].cumulativeSum() // [1, 3, 6, 10]
Implementation
List<num> cumulativeSum() {
if (this is! List<num>) {
throw UnsupportedError('cumulativeSum is only supported on List<num>');
}
final nums = this as List<num>;
final result = <num>[];
num running = 0;
for (final e in nums) {
running += e;
result.add(running);
}
return result;
}