Skip to main content

accumulate

Returns the result of accumulating all the values in the range (first,last) to init.

[1,2,3,4,5].accumulate(((a, b) => a + b), 0); // 0 + 1 + 2 + 3 + 4 + 5 = 15

Syntax

accumulate(callback, startValue)

Returns

The accumulated value.

Notes

  • The callback is expected to contain TWO parameters.
  • You MUST specify the startValue.