Calls the given reducer on each element of the given collection, passing its result as the accumulator to the next respective call, starting with the given initialValue. Returns all intermediate accumulator results.
The type of the elements in the array.
The type of the accumulator.
The array to reduce.
The reducer function to apply to each element.
The initial value of the accumulator.
An array of all intermediate accumulator results.
import { runningReduce } from "@std/collections/running-reduce";import { assertEquals } from "@std/assert";const numbers = [1, 2, 3, 4, 5];const sumSteps = runningReduce(numbers, (sum, current) => sum + current, 0);assertEquals(sumSteps, [1, 3, 6, 10, 15]); Copy
import { runningReduce } from "@std/collections/running-reduce";import { assertEquals } from "@std/assert";const numbers = [1, 2, 3, 4, 5];const sumSteps = runningReduce(numbers, (sum, current) => sum + current, 0);assertEquals(sumSteps, [1, 3, 6, 10, 15]);
Calls the given reducer on each element of the given collection, passing its result as the accumulator to the next respective call, starting with the given initialValue. Returns all intermediate accumulator results.