I generate the following json in my Node application:
[ { id: 1,
name: 'user1',
sport: 'athletics',
medal_count: '1'
},
{ id: 1,
name: 'user1',
sport: 'tennis',
medal_count: '2'
},
{ id: 2,
name: 'user2',
sport: ['football'],
medal_count: '2'
}
]
I'd now like to concatenate users so that they appear as a single object with the sport listed in an array and the medal_count aggegrated for the user. The above json would look like this:
[ { id: 1,
name: 'user1',
sport: [
'athletics',
'tennis'
],
medal_count: '3'
},
{ id: 2,
name: 'user2',
sport: 'football',
medal_count: '2'
}
]
How is this done? Am I correct in thinking this should be done with a map reduce function?