Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / createReduce.js
1 var baseCallback = require('./baseCallback'),
2     baseReduce = require('./baseReduce'),
3     isArray = require('../lang/isArray');
4
5 /**
6  * Creates a function for `_.reduce` or `_.reduceRight`.
7  *
8  * @private
9  * @param {Function} arrayFunc The function to iterate over an array.
10  * @param {Function} eachFunc The function to iterate over a collection.
11  * @returns {Function} Returns the new each function.
12  */
13 function createReduce(arrayFunc, eachFunc) {
14   return function(collection, iteratee, accumulator, thisArg) {
15     var initFromArray = arguments.length < 3;
16     return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
17       ? arrayFunc(collection, iteratee, accumulator, initFromArray)
18       : baseReduce(collection, baseCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
19   };
20 }
21
22 module.exports = createReduce;