I need help converting a list of team objects containing team names, reporters, and statuses for each day into date-based objects with all teams and their respective statuses for each date.
I attempted the following code snippet but did not achieve the desired outcome.
teams.map(team => ({
day: team.statuses.reduce((acc, it) => it.day),
teams: {
teamName: team.teamName
}
}))
[
{
"teamName":"abc",
"reportedBy": "user1",
"statuses":[
{
"day":"10/12",
"status":"green"
},
{
"day":"10/11",
"status":"green"
},
{
"day":"10/09",
"status":"green"
}
]
},
{
"teamName":"xyz",
"reportedBy": "user2",
"statuses":[
{
"day":"10/12",
"status":"red"
},
{
"day":"10/11",
"status":"red"
},
{
"day":"10/09",
"status":"red"
}
]
}
]
The expected output should be:
[
{
"day": "1012",
"teams": [
{
"teamName": "abc",
"reportedBy": "user1",
"status": "green"
},
{
"teamName": "xyz",
"reportedBy": "user2",
"status": "red"
}
]
},
{
"day": "1011",
"teams": [
{
"teamName": "abc",
"reportedBy": "user1",
"status": "green"
},
{
"teamName": "xyz",
"reportedBy": "user2",
"status": "red"
}
]
},
{
"day": "1009",
"teams": [
{
"teamName": "abc",
"reportedBy": "user1",
"status": "green"
},
{
"teamName": "xyz",
"reportedBy": "user2",
"status": "red"
}
]
}
]