I'm trying to make a simple "top 3" of the users that have the most messages. So far I was able to group the user and messages inside an array of objects
let data = [ { message: 'fsaasfafs', user: 'John' },
{ message: 'asgsgaasgags', user: 'John' },
{ message: 'asgsgaasgags', user: 'John' },
{ message: 'asgsgaasgags', user: 'Smith' },
{ message: 'asgsgaasgags', user: 'Samantha' },
{ message: 'asgsgaasgags', user: 'Luis' },
{ message: 'asgsgaasgags', user: 'Samantha' }]
console.log(data);
In this case, the top 3 would be John - 3 ; Samantha - 2; Smith or Luis (does not matter) - 1 I would like a map with the user as key and the amount of messages.
Any help please?