// 1. Вернуть объект с ключами type из масива,
// значение - массив элементов с таким type
 
// 2. Вернуть объект с ключами type, а значение - объект
// вида {count: количество, weight: суммарный вес}
 
const arr = [
{ type: 'banana', weight: 32 },
{ type: 'apple', weight: 24 },
{ type: 'kiwi', weight: 55 },
{ type: 'banana', weight: 44 },
{ type: 'orange', weight: 5 },
{ type: 'orange', weight: 10 },
];
 
const groupByType = arr => {
const res = {};
arr.forEach(fruit => {
if (!res[fruit.type]) {
res[fruit.type] = { count: 0, weight: 0 };
}
 
res[fruit.type].count += 1;
res[fruit.type].weight += fruit.weight;
});
 
return res;
};
 
console.log(groupByType(arr));
 
Code will run automatically after changes.
Code runs in an isolated environment.