cumulativeSum

Returns one running total per input value.

import { Arith } from "@teakit/arith";

Arith.cumulativeSum(["1", "2", "3"]).map((x) => x.toString()); // ["1", "3", "6"]
Arith.cumulativeSum(["1.1", "-0.1", "2"]).map((x) => x.toString()); // ["1.1", "1", "3"]
Arith.cumulativeSum([]); // []

API Reference

Signature

Arith.cumulativeSum(values: readonly ArithValue[]): ArithInstance[];

Parameters

ParameterTypeRequiredNotes
valuesreadonly ArithValue[]YesArray of finite values. Empty arrays are allowed.

Returns

Returns an ArithInstance[] with the same length as values.

Throws

  • Throws if values is not an array.
  • Throws if any value is non-finite.

Agent Contract

FieldValue
Kindstatic method
Canonical namecumulativeSum
AliasesNone
Mutates receiverNo
ReturnsArithInstance[]
Accepts (string, base) overloadNo
Configuration dependenciesSTRICT
Related methodssum, cumulativeMul

Agent Notes

  • Empty input returns [].
  • Use this for running balances or cumulative report rows.