mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +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
|
* @private
|
||||||
* @param {Array} array The array to iterate over.
|
* @param {Array} array The array to iterate over.
|
||||||
|
* @param {Function} iteratee The function invoked per iteration.
|
||||||
* @returns {number} Returns the sum.
|
* @returns {number} Returns the sum.
|
||||||
*/
|
*/
|
||||||
function arraySum(array) {
|
function arraySum(array, iteratee) {
|
||||||
var length = array.length,
|
var length = array.length,
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
while (length--) {
|
while (length--) {
|
||||||
result += +array[length] || 0;
|
result += +iteratee(array[length]) || 0;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -11948,15 +11950,9 @@
|
|||||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||||
iteratee = undefined;
|
iteratee = undefined;
|
||||||
}
|
}
|
||||||
var callback = getCallback(),
|
iteratee = getCallback(iteratee, thisArg, 3);
|
||||||
noIteratee = iteratee == null;
|
return iteratee.length == 1
|
||||||
|
? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee)
|
||||||
if (!(noIteratee && callback === baseCallback)) {
|
|
||||||
noIteratee = false;
|
|
||||||
iteratee = callback(iteratee, thisArg, 3);
|
|
||||||
}
|
|
||||||
return noIteratee
|
|
||||||
? arraySum(isArray(collection) ? collection : toIterable(collection))
|
|
||||||
: baseSum(collection, iteratee);
|
: baseSum(collection, iteratee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user