Realmente no sé cómo reducir el método, traté de usar esto para obtener el siguiente JSON, pero obviamente no funcionó.
{ "w_elem": [ { "item": [ {"type": "type_a","price": "100","discount": "10"}, {"type": "type_b","price": "120","discount": "12"}, {"type": "type_a","price": "165","discount": "10"} ], "user": "1001", "userType": "A" }, { "item": [ {"type": "type_a","price": "85","discount": "5"}, {"type": "type_a","price": "15","discount": "0"} ], "user": "1002", "userType": "B" } ] }``` w_elem.forEach(elem => { let user= elem.user; let aa = Object.values(elem.item.reduce((acc, {type, price, discount}) => { acc[type] = acc[type] || {type, price: 0, discount: 0, Count: 0}; acc[type].price+= Number(price); acc[type].discount+= Number(discount); acc[type].Count += 1; return acc; },{})); });```traté de hacer lo siguiente
{ "user": "1001", "item": [ {"type": "type_a","price": "265","discount": "20"}, {"type": "type_b","price": "120","discount": "12"}, ] }, { "user": "1002", "item": [ {"type": "type_a","price": "85","discount": "5"}, {"type": "type_b","price": "15","discount": "0"} ] } ]no entiendo cómo mantener la estructura y solo agrupar elementos por tipo usando reducir