_baseMean.js 568 B

123456789101112131415161718192021
  1. var baseSum = require('./_baseSum');
  2. /** Used as references for various `Number` constants. */
  3. var NAN = 0 / 0;
  4. /**
  5. * The base implementation of `_.mean` and `_.meanBy` without support for
  6. * iteratee shorthands.
  7. *
  8. * @private
  9. * @param {Array} array The array to iterate over.
  10. * @param {Function} iteratee The function invoked per iteration.
  11. * @returns {number} Returns the mean.
  12. */
  13. function baseMean(array, iteratee) {
  14. var length = array == null ? 0 : array.length;
  15. return length ? (baseSum(array, iteratee) / length) : NAN;
  16. }
  17. module.exports = baseMean;