I am sure there is already an answer as well as an "easy" solution to this, but I did not find something in the last hour.
So I have this object:
[
{
"win": false,
"switched": false
},
{
"win": false,
"switched": false
},
{
"win": true,
"switched": true
},
{
"win": true,
"switched": true
}
]
which is showing the results of four monty-hall games. I want to create an object from this array that would have the following structure:
{
switched: {
played: 2,
won: 2
},
put: {
played: 2,
lost: 2
}
}
So actually if the object in the upper array has switched: true I want to increase the value of switched["played"]by 1 and it has also won: true I want to increase the value of the keys switched["won"] also by one. Vice versa for switched: false I wand to put everything in the results-object under the key put.
I tried some rather embarrassing approaches with reduce, but I think there must be an "easier" way (mine did not work at all...)