arraySum.js 491 B

1234567891011121314151617181920
  1. /**
  2. * A specialized version of `_.sum` for arrays without support for callback
  3. * shorthands and `this` binding..
  4. *
  5. * @private
  6. * @param {Array} array The array to iterate over.
  7. * @param {Function} iteratee The function invoked per iteration.
  8. * @returns {number} Returns the sum.
  9. */
  10. function arraySum(array, iteratee) {
  11. var length = array.length,
  12. result = 0;
  13. while (length--) {
  14. result += +iteratee(array[length]) || 0;
  15. }
  16. return result;
  17. }
  18. module.exports = arraySum;