Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/proc/mod3.ts>Enumerable#reduce

A better way to work with processes in Deno.
Latest
method Enumerable.prototype.reduce
Re-export
import { Enumerable } from "https://deno.land/x/proc@0.21.9/mod3.ts";

Executes a user-supplied "reducer" callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.

Parameters

reduceFn: (
acc: T,
item: T,
index: number,
) => T | Promise<T>

A function to execute for each element in the array. Its return value becomes the value of the accumulator parameter on the next invocation of reduceFn. For the last invocation, the return value becomes the return value of reduce().

Returns

Promise<T>

The value that results from running the "reducer" callback function to completion over the entire array.

Executes a user-supplied "reducer" callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.

Parameters

reduceFn: (
acc: U,
item: T,
index: number,
) => U | Promise<U>

A function to execute for each element in the array. Its return value becomes the value of the accumulator parameter on the next invocation of reduceFn. For the last invocation, the return value becomes the return value of reduce().

zero: U

A value to which accumulator is initialized the first time the callback is called.

Returns

Promise<U>

The value that results from running the "reducer" callback function to completion over the entire array.