UNPKG

531 BJavaScriptView Raw
1var groupBy = require('./groupBy')
2
3var objectEach = require('./objectEach')
4
5/**
6 * 集合分组统计,返回各组中对象的数量统计
7 *
8 * @param {Array} obj 对象
9 * @param {Function} iterate 回调/对象属性
10 * @param {Object} context 上下文
11 * @return {Object}
12 */
13function countBy (obj, iterate, context) {
14 var result = groupBy(obj, iterate, context || this)
15 objectEach(result, function (item, key) {
16 result[key] = item.length
17 })
18 return result
19}
20
21module.exports = countBy