UNPKG

@arrows/array

Version:
37 lines (36 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reduceRight = void 0; const curry_1 = require("@arrows/composition/curry"); const _reduceRightFirst = (reducingFn, arr) => arr.reduce(reducingFn); const reduceRightFirst = curry_1.default(_reduceRightFirst); const _reduceRight = (reducingFn, initialValue, arr) => arr.reduceRight(reducingFn, initialValue); const curriedReduceRight = curry_1.default(_reduceRight); /** * Functional wrapper for Array.prototype.reduceRight * * Calls the specified callback function for all the elements in an array, * in descending order. * The return value of the reducing function is the accumulated result, * and is provided as an argument in the next call to the reducing function. * * @param reducingFn Reducing function * @param initialValue Initial value of the accumulator * @param arr Initial array * @returns Final accumulator value * * @method first Reduce without initializer */ const reduceRight = Object.assign(curriedReduceRight, { /** * Reduce without initializer. * The last element of the array will be used as an initial accumulator. * * @param reducingFn Reducing function * @param arr Initial array * @returns Final accumulator value */ first: reduceRightFirst, }); exports.reduceRight = reduceRight; exports.default = reduceRight;