baseSum.js 569 B

1234567891011121314151617181920
  1. var baseEach = require('./baseEach');
  2. /**
  3. * The base implementation of `_.sum` without support for callback shorthands
  4. * and `this` binding.
  5. *
  6. * @private
  7. * @param {Array|Object|string} collection The collection to iterate over.
  8. * @param {Function} iteratee The function invoked per iteration.
  9. * @returns {number} Returns the sum.
  10. */
  11. function baseSum(collection, iteratee) {
  12. var result = 0;
  13. baseEach(collection, function(value, index, collection) {
  14. result += +iteratee(value, index, collection) || 0;
  15. });
  16. return result;
  17. }
  18. module.exports = baseSum;