mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Bump to v4.0.0.
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
import baseEach from './baseEach';
|
||||
|
||||
/**
|
||||
* The base implementation of `_.sum` without support for callback shorthands
|
||||
* and `this` binding.
|
||||
* The base implementation of `_.sum` without support for iteratee shorthands.
|
||||
*
|
||||
* @private
|
||||
* @param {Array|Object|string} collection The collection to iterate over.
|
||||
* @param {Array} array The array to iterate over.
|
||||
* @param {Function} iteratee The function invoked per iteration.
|
||||
* @returns {number} Returns the sum.
|
||||
*/
|
||||
function baseSum(collection, iteratee) {
|
||||
var result = 0;
|
||||
baseEach(collection, function(value, index, collection) {
|
||||
result += +iteratee(value, index, collection) || 0;
|
||||
});
|
||||
function baseSum(array, iteratee) {
|
||||
var result,
|
||||
index = -1,
|
||||
length = array.length;
|
||||
|
||||
while (++index < length) {
|
||||
var current = iteratee(array[index]);
|
||||
if (current !== undefined) {
|
||||
result = result === undefined ? current : (result + current);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user