I need create a scoreboard for these players, based on an array of games. Each game has a final score with multiple p[layers. Each player has a property for what team they played. that property needs to be used to sum up the scores for each game.
The data looks like this:
var games = [
{
'id': '1',
"teamOneScore": 10,
"teamTwoScore": 5,
'players': [
{
"username": "waters",
"displayName": "Waters Adkins",
"gender": "M",
"image": null,
"team": 2,
"appUserId": "86ba61dd-df18-4c42-b788-1d859507bab1"
},
{
"username": "whitney",
"displayName": "Whitney Winters",
"gender": "F",
"image": null,
"team": 1,
"appUserId": "c22bfafa-337a-4cbd-840d-e60adeb23625"
}
]
}, {
'id': '4',
"teamOneScore": 25,
"teamTwoScore": 10,
'players': [
{
"username": "waters",
"displayName": "Waters Adkins",
"gender": "M",
"image": null,
"team": 2,
"appUserId": "86ba61dd-df18-4c42-b788-1d859507bab1"
},
{
"username": "whitney",
"displayName": "Whitney Winters",
"gender": "F",
"image": null,
"team": 1,
"appUserId": "c22bfafa-337a-4cbd-840d-e60adeb23625"
}
]
}, {
'id': '6',
"teamOneScore": 10,
"teamTwoScore": 5,
'players': [
{
"username": "waters",
"displayName": "Waters Adkins",
"gender": "M",
"image": null,
"team": 2,
"appUserId": "86ba61dd-df18-4c42-b788-1d859507bab1"
},
{
"username": "whitney",
"displayName": "Whitney Winters",
"gender": "F",
"image": null,
"team": 1,
"appUserId": "c22bfafa-337a-4cbd-840d-e60adeb23625"
}
]
}
];
The result should be an array of players with total score property added to it.
'players': [
{
"username": "waters",
"displayName": "Waters Adkins",
"gender": "M",
"totalScore": 20,
"appUserId": "86ba61dd-df18-4c42-b788-1d859507bab1",
},
{
"username": "whitney",
"displayName": "Whitney Winters",
"gender": "F",
"totalScore": 45,
"appUserId": "c22bfafa-337a-4cbd-840d-e60adeb23625"
}
]```