1 var arrayReduceRight = require('./internal/arrayReduceRight'),
2 baseEachRight = require('./internal/baseEachRight'),
3 baseIteratee = require('./internal/baseIteratee'),
4 baseReduce = require('./internal/baseReduce'),
5 isArray = require('./isArray');
8 * This method is like `_.reduce` except that it iterates over elements of
9 * `collection` from right to left.
13 * @category Collection
14 * @param {Array|Object} collection The collection to iterate over.
15 * @param {Function} [iteratee=_.identity] The function invoked per iteration.
16 * @param {*} [accumulator] The initial value.
17 * @returns {*} Returns the accumulated value.
20 * var array = [[0, 1], [2, 3], [4, 5]];
22 * _.reduceRight(array, function(flattened, other) {
23 * return flattened.concat(other);
25 * // => [4, 5, 2, 3, 0, 1]
27 function reduceRight(collection, iteratee, accumulator) {
28 var func = isArray(collection) ? arrayReduceRight : baseReduce,
29 initAccum = arguments.length < 3;
31 return func(collection, baseIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
34 module.exports = reduceRight;