1 var baseCallback = require('./baseCallback'),
2 baseReduce = require('./baseReduce'),
3 isArray = require('../lang/isArray');
6 * Creates a function for `_.reduce` or `_.reduceRight`.
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.
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);
22 module.exports = createReduce;