Files
lodash/.internal/baseSum.js
John-David Dalton 3e2b0bb763 Use more for-of
2017-04-03 10:36:11 -07:00

22 lines
490 B
JavaScript

/**
* The base implementation of `sum` and `sumBy`.
*
* @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) {
let result
for (value of array) {
const current = iteratee(value)
if (current !== undefined) {
result = result === undefined ? current : (result + current)
}
}
return result
}
export default baseSum