3π
β
In one chain, just for fun.
_.chain(data)
.groupBy('status')
.mapObject(x => x.length)
.pairs()
.unzip()
.zip(['legend', 'data'])
.map(x => x.reverse())
.object()
.value();
0π
Just need one more step:
var output = {
legend: [],
data: []
}
_.chain(rawData).groupBy('status').each(function(value,key){
output.legend.push(key);
output.legend.push(data.length);
})
0π
var legend = _.uniq(_.pluck(data, 'status'));
var groupedData = _.groupBy(data, 'status');
var result = {
legend: legend,
data: _.map(legend, function(status) {
return groupedData[status].length;
})
};
Source:stackexchange.com