Skip to main content

reduce()

reduce<T, R>(fn): (initVal) => (arr) => R

Calls the accumulator with each element of the given array, starting with the first element. Returns the final result.

Type Parameters

T

R

Parameters

fn

Accumulator<T, R>

The accumulator function to apply to each element of the array.

Returns

Function

Parameters

initVal

R

Returns

Function

Parameters

arr

T[]

Returns

R

Remarks

pure function

Example

import { reduce } from '@accelint/core';

reduce((total, n) => total + n)(0)([1, 2, 3, 4, 5]);
// 15