Chartjs-UndescoreJS – Convert Object Properties Into Arrays

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;
    })
};

Leave a comment