Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_baseSum.js 600B

123456789101112131415161718192021222324
  1. /**
  2. * The base implementation of `_.sum` and `_.sumBy` without support for
  3. * iteratee shorthands.
  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 baseSum(array, iteratee) {
  11. var result,
  12. index = -1,
  13. length = array.length;
  14. while (++index < length) {
  15. var current = iteratee(array[index]);
  16. if (current !== undefined) {
  17. result = result === undefined ? current : (result + current);
  18. }
  19. }
  20. return result;
  21. }
  22. module.exports = baseSum;