1 | var groupBy = require('./groupBy')
|
2 |
|
3 | var objectEach = require('./objectEach')
|
4 |
|
5 | /**
|
6 | * 集合分组统计,返回各组中对象的数量统计
|
7 | *
|
8 | * @param {Array} obj 对象
|
9 | * @param {Function} iterate 回调/对象属性
|
10 | * @param {Object} context 上下文
|
11 | * @return {Object}
|
12 | */
|
13 | function 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 |
|
21 | module.exports = countBy
|