Rename arraySum to baseSum.

This commit is contained in:
John-David Dalton
2015-08-29 09:16:48 -07:00
parent 4d2aa29926
commit f79148fa62

View File

@@ -1450,26 +1450,6 @@
return false;
}
/**
* A specialized version of `_.sum` for arrays without support for callback
* shorthands.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {number} Returns the sum.
*/
function arraySum(array, iteratee) {
var index = -1,
length = array.length,
result = 0;
while (++index < length) {
result += +iteratee(array[index]) || 0;
}
return result;
}
/**
* Assigns `value` to `key` of `object` if the existing value is not equivalent
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
@@ -2652,6 +2632,25 @@
return result;
}
/**
* The base implementation of `_.sum` without support for callback shorthands.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {number} Returns the sum.
*/
function baseSum(array, iteratee) {
var index = -1,
length = array.length,
result = 0;
while (++index < length) {
result += +iteratee(array[index]) || 0;
}
return result;
}
/**
* The base implementation of `_.times` without support for callback shorthands
* or max array length checks.
@@ -11362,7 +11361,7 @@
* // => 10
*/
function sum(array) {
return array ? arraySum(array, identity) : 0;
return array ? baseSum(array, identity) : 0;
}
/**
@@ -11392,7 +11391,7 @@
*/
function sumBy(array, iteratee) {
return (array && array.length)
? arraySum(array, getIteratee(iteratee))
? baseSum(array, getIteratee(iteratee))
: 0;
}