You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
510 B
22 lines
510 B
5 months ago
|
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
|