mean.js 443 B

12345678910111213141516171819
  1. var helperNumberDivide = require('./helperNumberDivide')
  2. var getSize = require('./getSize')
  3. var sum = require('./sum')
  4. /**
  5. * 求平均值函数
  6. *
  7. * @param {Array} array 数组
  8. * @param {Function/String} iterate 方法或属性
  9. * @param {Object} context 上下文
  10. * @return {Number}
  11. */
  12. function mean (array, iterate, context) {
  13. return helperNumberDivide(sum(array, iterate, context), getSize(array))
  14. }
  15. module.exports = mean