Files
lodash/internal/arrayReduceRight.js
John-David Dalton f9606b394c Bump to v3.0.0.
2015-02-04 00:38:56 -08:00

25 lines
785 B
JavaScript

/**
* A specialized version of `_.reduceRight` for arrays without support for
* callback shorthands or `this` binding.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value.
* @param {boolean} [initFromArray] Specify using the last element of `array`
* as the initial value.
* @returns {*} Returns the accumulated value.
*/
function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
var length = array.length;
if (initFromArray && length) {
accumulator = array[--length];
}
while (length--) {
accumulator = iteratee(accumulator, array[length], length, array);
}
return accumulator;
}
module.exports = arrayReduceRight;