Implementing JavaScript functional programming techniques, how can the `status` field of `arr1` be aggregated/counted and then transformed into an array of key/value objects in `arr2`?
arr1 = [
{'task':'do something 1', 'status':'done'} ,
{'task':'do something 2', 'status':'done'} ,
{'task':'do something 3', 'status':'pending'} ,
{'task':'do something 4', 'status':'done'}
];
// Aggregate arr1 `status` field and transform to:
arr2 = [
{key:'done', value: 3},
{key:'pending', value: 1}
];
Outlined below is my work-in-progress solution that currently addresses only the aggregation part. The transformation part still needs to be implemented.
var arr2 = arr1.map(function(item) {
return item.status;
}).reduce(function(acc,curr,idx){
if(acc[curr] === undefined) acc[curr] = 1;
else acc[curr] += 1;
return acc;
}, []);