1
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
var groupBy = require('./groupBy')
|
||||
|
||||
var objectEach = require('./objectEach')
|
||||
|
||||
/**
|
||||
* 集合分组统计,返回各组中对象的数量统计
|
||||
*
|
||||
* @param {Array} obj 对象
|
||||
* @param {Function} iterate 回调/对象属性
|
||||
* @param {Object} context 上下文
|
||||
* @return {Object}
|
||||
*/
|
||||
function countBy (obj, iterate, context) {
|
||||
var result = groupBy(obj, iterate, context || this)
|
||||
objectEach(result, function (item, key) {
|
||||
result[key] = item.length
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
module.exports = countBy
|
||||
Reference in New Issue
Block a user