Greetings from Romania,
Given a list of games, which are objects that look like:
{
"id": 112814,
"matches": "123",
"tries": "11"
}
return a object like such
{
"totalMatches": m,
"totalTries": y
}
Where m is the sum of all matches for all games and t is the sum of all tries for all games.
input = [
{"id": 1,"matches": "123","tries": "11"},
{"id": 2,"matches": "1","tries": "1"},
{"id": 3,"matches": "2","tries": "5"}
]
output = {
matches: 126,
tries: 17
}
What I currently have:
function countStats(list) {
return {
matches: 0,
tries: 0
};
}
What I think I need to do:
- Iterate through all objects
- Use global variable to count matches (m) and tries (y)
- Return m, y respectively
What I was told to do instead, which I do not know how: 1. Use the reduce function 2. Return an object instead
Many thanks for any advice