arrayCumSum function Null safety

Array arrayCumSum(
  1. Array a
)

Return the array with accumulative sum of all elements of the array

Examples

var n = Array([1, 2, 3]);

print(arrayCumSum(n));

/* expected output:
Array([1.0, 3.0, 6.0])
*/

Implementation

Array arrayCumSum(Array a) {
  var sum = 0.0;
  var b = Array.empty();
  for (var i = 0; i < a.length; i++) {
    sum += a[i];
    b.add(sum);
  }
  return b;
}