mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Simplify _.sum.
This commit is contained in:
@@ -1606,18 +1606,20 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* A specialized version of `_.sum` for arrays without support for iteratees.
|
||||
* A specialized version of `_.sum` for arrays without support for callback
|
||||
* shorthands and `this` binding..
|
||||
*
|
||||
* @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) {
|
||||
function arraySum(array, iteratee) {
|
||||
var length = array.length,
|
||||
result = 0;
|
||||
|
||||
while (length--) {
|
||||
result += +array[length] || 0;
|
||||
result += +iteratee(array[length]) || 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -11948,15 +11950,9 @@
|
||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||
iteratee = undefined;
|
||||
}
|
||||
var callback = getCallback(),
|
||||
noIteratee = iteratee == null;
|
||||
|
||||
if (!(noIteratee && callback === baseCallback)) {
|
||||
noIteratee = false;
|
||||
iteratee = callback(iteratee, thisArg, 3);
|
||||
}
|
||||
return noIteratee
|
||||
? arraySum(isArray(collection) ? collection : toIterable(collection))
|
||||
iteratee = getCallback(iteratee, thisArg, 3);
|
||||
return iteratee.length == 1
|
||||
? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee)
|
||||
: baseSum(collection, iteratee);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user