Array
/ API Reference
Array
/ API Reference

reduce

Reduces the array based on the provided reducer function.
Similar to Array.prototype.reduce.

The Gist

import { reduce } from '@weser/array'

const reducedArray = reduce(
  [1, 2, 3],
  (accumulator, value) => accumulator + value,
  0
)

// => 6
console.log(reducedArray)

Parameters

ParameterTypeDescription
arrArray<T>The array to reduce.
reducer(accumulator: B, value: T, index: number, length: number, array: Array<T>) => BThe reducer function.
initialValueBThe initial value.

Returns

(B) The reduced value.

On this page