JavaScript: Group an array according to type

Full stack developer (ReactJS, NodeJS, JavaScript, PHP, SQL)
const array = [
{ type: 'A', status:'Approved' },
{ type: 'A', status:'Approved' },
{ type: 'A', status:'Disapproved' },
{ type: 'A', status:'Disapproved' },
{ type: 'A', status:'Processing' },
{ type: 'B', status:'Processing' },
{ type: 'B', status:'Approved' },
{ type: 'B', status:'Disapproved' },
];
const reducedObject = array.reduce((rv,x) =>{
if(!rv[x.type]) {
rv[x.type] = {
type: x.type,
Approved: 0,
Disapproved: 0,
Processing: 0
}
}
rv[x.type][x.status]++;
return rv;
}, {});
const desiredArray = Object.values(reducedObject);
console.log(desiredArray);
Output:
[
{ type: 'A', Approved: 2, Disapproved: 2, Processing: 1 },
{ type: 'B', Approved: 1, Disapproved: 1, Processing: 1 }
]




