const filterData = (cars) => {
const defaultObj = {
type: {}
};
return cars.reduce((acc, car) => {
const { name, id } = car.type;
if (car.type && name in acc.type) {
acc.type[name].count += 1;
} else if (car.type) {
acc.type[name] = {
id,
count: 1,
name: 'type',
};
}
return acc;
}, defaultObj);
};