I need to display the countries with the most users. In order from largest to smallest (and additionally max 10 countries). How can I achieve it?
let users = {
1: {
name: "Name1",
country: "US",
},
2: {
name: "Name2",
country: "US",
},
3: {
name: "Name3",
country: "FR",
},
4: {
name: "Name4",
country: "DE",
},
};
groupBy(users, "country", "asc")
And I get an array like:
{
DE: array(),
US: array(),
FR: array()
}
How can I sort this data? I need to return the number of users by country. I would like to receive something like this:
{
US: 2
DE: 1,
FR: 1
}
I am using some Lodash functions (imports them one at a time)