@monstermann/fn
Version:
A utility library for TypeScript.
25 lines (23 loc) • 543 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/array/reduce.ts
/**
* `reduce(array, initial, reducer)`
*
* Reduces `array` to a single value by executing the `reducer` function on each element, starting with the `initial` accumulator value.
*
* ```ts
* reduce([1, 2, 3, 4], 0, (acc, x) => acc + x); // 10
* ```
*
* ```ts
* pipe(
* [1, 2, 3, 4],
* reduce(0, (acc, x) => acc + x),
* ); // 10
* ```
*/
const reduce = dfdlT((target, acc, reducer) => {
return target.reduce(reducer, acc);
}, 3);
//#endregion
export { reduce };