mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 01:17:50 +00:00
Ensure _.sum provides the correct arguments when iterating an object.
This commit is contained in:
@@ -1699,6 +1699,16 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
function arraySum(array) {
|
||||
var length = array.length,
|
||||
result = 0;
|
||||
|
||||
while (length--) {
|
||||
result += +array[length] || 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by `_.defaults` to customize its `_.assign` use.
|
||||
*
|
||||
@@ -2747,6 +2757,14 @@
|
||||
});
|
||||
}
|
||||
|
||||
function baseSum(collection, iteratee) {
|
||||
var result = 0;
|
||||
baseEach(collection, function(value, index, collection) {
|
||||
result += +iteratee(value, index, collection) || 0;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The base implementation of `_.uniq` without support for callback shorthands
|
||||
* and `this` binding.
|
||||
@@ -11333,9 +11351,6 @@
|
||||
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
||||
iteratee = null;
|
||||
}
|
||||
if (!isArray(collection)) {
|
||||
collection = toIterable(collection);
|
||||
}
|
||||
var func = getCallback(),
|
||||
noIteratee = iteratee == null;
|
||||
|
||||
@@ -11343,14 +11358,9 @@
|
||||
noIteratee = false;
|
||||
iteratee = func(iteratee, thisArg, 3);
|
||||
}
|
||||
var length = collection.length,
|
||||
result = 0;
|
||||
|
||||
while (length--) {
|
||||
var value = collection[length];
|
||||
result += +(noIteratee ? value : iteratee(value)) || 0;
|
||||
}
|
||||
return result;
|
||||
return noIteratee
|
||||
? arraySum(isArray(collection) ? collection : toIterable(collection))
|
||||
: baseSum(collection, iteratee);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user