Loops
/ API Reference
Loops
/ API Reference

arrayReduce

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

The Gist

import { arrayReduce } from '@weser/loops'

const reducedArray = arrayReduce(
  [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