码迷,mamicode.com
首页 > 其他好文 > 详细

lodash group by and sum

时间:2016-01-08 18:52:47      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:

var data=[{value:1200,count:5},{value:1200,count:10},{value:1230,count:5},{value:1240,count:5}];
console.log(_.chain(data)
    .groupBy("value")
    .map(function(value, key) {
        return [key, _.reduce(value, function(result, currentObject) {
            return {
                value: currentObject.value,
                count: result.count+ currentObject.count
            }
        }, {
            value: 0,
            count: 0
        })];
    })
    .object()
    .value());

  lodash js数组分组汇总

lodash group by and sum

标签:

原文地址:http://www.cnblogs.com/AskySun/p/5114104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!