af62c6c191d242b7c1b32ef181dc758a84a3b1e9
[yaffs-website] / node_modules / grunt-legacy-util / node_modules / lodash / reduceRight.js
1 var arrayReduceRight = require('./_arrayReduceRight'),
2     baseEachRight = require('./_baseEachRight'),
3     baseIteratee = require('./_baseIteratee'),
4     baseReduce = require('./_baseReduce'),
5     isArray = require('./isArray');
6
7 /**
8  * This method is like `_.reduce` except that it iterates over elements of
9  * `collection` from right to left.
10  *
11  * @static
12  * @memberOf _
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.
18  * @example
19  *
20  * var array = [[0, 1], [2, 3], [4, 5]];
21  *
22  * _.reduceRight(array, function(flattened, other) {
23  *   return flattened.concat(other);
24  * }, []);
25  * // => [4, 5, 2, 3, 0, 1]
26  */
27 function reduceRight(collection, iteratee, accumulator) {
28   var func = isArray(collection) ? arrayReduceRight : baseReduce,
29       initAccum = arguments.length < 3;
30
31   return func(collection, baseIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
32 }
33
34 module.exports = reduceRight;