I have an array of objects as follows:
var data = [
{
"count": 1,
"make": "ALFA ROMEO",
"model": "GIULIETTA DIESEL - 2010"
},
{
"count": 2,
"make": "AUDI",
"model": "A1 DIESEL"
},
{
"count": 1,
"make": "AUDI",
"model": "A1 SPORTBACK DIESEL"
},
{
"count": 2,
"make": "AUDI",
"model": "A3 DIESEL - 2012"
},
{
"count": 3,
"make": "Volkswagen",
"model": "Golf"
},
{
"count": 3,
"make": "Ford",
"model": "Escord"
},
{
"count": 2,
"make": "Opel",
"model": "Zafira"
}
]
I want to group by
it by make
and then get three makes with the highest count and the rest I will to show as other.
For example I want to get:
var result = [
{
"brand": "Audi",
"count": 5
},
{
"brand": "Volkswagen",
"count": 3
},
{
"brand": "Ford",
"count": 3
},
{
"brand": "Other",
"count": 3
}
]
I have no idea how to start. Any help?