I'm trying to find the sum of each type in my array of roomList... Tried out reduce() but it is only returning the last value. Is there a way to achieve this using reduce()... I'm open to other approaches also.
let roomList=[
{value:1,type:2},{value:2,type:2},{value:3,type:2},{value:4,type:3},
{value:5,type:4},{value:6,type:4},{value:7,type:6},{value:8,type:6},
{value:9,type:1},{value:10,type:8},{value:11,type:8},{value:12,type:8}
];
roomList.reduce((acc,obj)=>{
acc[obj.type]=obj.value;
return acc;
},{})
I'm expecting a result like this {1:9,2:6,3:4,4:11...}