Loops
/ API ReferenceLoops
/ API ReferencearrayReduce
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
Parameter | Type | Description |
---|---|---|
arr | Array<T> | The array to reduce. |
reducer | (accumulator: B, value: T, index: number, length: number, array: Array<T>) => B | The reducer function. |
initialValue | B | The initial value. |
Returns
(B
) The reduced value.
© 2024-present Robin Weser. All Rights Reserved.