X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=node_modules%2Fgrunt-legacy-util%2Fnode_modules%2Flodash%2Freduce.js;fp=node_modules%2Fgrunt-legacy-util%2Fnode_modules%2Flodash%2Freduce.js;h=98da3ff0a2219d6c63a8ce0c6ee3093b37e7c62e;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/node_modules/grunt-legacy-util/node_modules/lodash/reduce.js b/node_modules/grunt-legacy-util/node_modules/lodash/reduce.js new file mode 100644 index 000000000..98da3ff0a --- /dev/null +++ b/node_modules/grunt-legacy-util/node_modules/lodash/reduce.js @@ -0,0 +1,49 @@ +var arrayReduce = require('./_arrayReduce'), + baseEach = require('./_baseEach'), + baseIteratee = require('./_baseIteratee'), + baseReduce = require('./_baseReduce'), + isArray = require('./isArray'); + +/** + * Reduces `collection` to a value which is the accumulated result of running + * each element in `collection` through `iteratee`, where each successive + * invocation is supplied the return value of the previous. If `accumulator` + * is not given the first element of `collection` is used as the initial + * value. The iteratee is invoked with four arguments: + * (accumulator, value, index|key, collection). + * + * Many lodash methods are guarded to work as iteratees for methods like + * `_.reduce`, `_.reduceRight`, and `_.transform`. + * + * The guarded methods are: + * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`, + * and `sortBy` + * + * @static + * @memberOf _ + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @returns {*} Returns the accumulated value. + * @example + * + * _.reduce([1, 2], function(sum, n) { + * return sum + n; + * }, 0); + * // => 3 + * + * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { + * (result[value] || (result[value] = [])).push(key); + * return result; + * }, {}); + * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) + */ +function reduce(collection, iteratee, accumulator) { + var func = isArray(collection) ? arrayReduce : baseReduce, + initAccum = arguments.length < 3; + + return func(collection, baseIteratee(iteratee, 4), accumulator, initAccum, baseEach); +} + +module.exports = reduce;