mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17:50 +00:00
Rename arraySum to baseSum.
This commit is contained in:
43
lodash.js
43
lodash.js
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user