scan
Like reduce but returns an array of all intermediate accumulator values.
The result array starts with the initial value and ends with the final
accumulator, so its length is array.length + 1.
Usage
scan<T, R>(array: readonly T[], fn: (accumulator: R, value: T, index: number) => R, initial: R)
Like reduce but returns an array of all intermediate accumulator values.
The result array starts with the initial value and ends with the final
accumulator, so its length is array.length + 1.
Parameters
arrayreadonly T[]required
the source array.
fn(accumulator: R, value: T, index: number) => Rrequired
the function to apply.
initialRrequired
the initial accumulator value.
Returns
an array containing the initial value followed by every intermediate accumulator.