Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fathym_common/src/src.deps.ts>runningReduce

The Fathym Reference Architecture provides the common foundation for applications built in Typescript.
Go to Latest
function runningReduce
import { runningReduce } from "https://deno.land/x/fathym_common@v0.0.143/src/src.deps.ts";

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.

Examples

Example 1

import { runningReduce } from "https://deno.land/std@0.224.0/collections/running_reduce.ts";
import { assertEquals } from "https://deno.land/std@0.224.0/assert/assert_equals.ts";

const numbers = [1, 2, 3, 4, 5];
const sumSteps = runningReduce(numbers, (sum, current) => sum + current, 0);

assertEquals(sumSteps, [1, 3, 6, 10, 15]);

Parameters

array: readonly T[]
reducer: (
accumulator: O,
current: T,
currentIndex: number,
) => O
initialValue: O