I have a collection of objects that looks like this:
var information = [
{
"quantity": 1,
"make": "ALFA ROMEO",
"model": "GIULIETTA DIESEL - 2010"
},
{
"quantity": 2,
"make": "AUDI",
"model": "A1 DIESEL"
},
{
"quantity": 1,
"make": "AUDI",
"model": "A1 SPORTBACK DIESEL"
},
{
"quantity": 2,
"make": "AUDI",
"model": "A3 DIESEL - 2012"
},
{
"quantity": 3,
"make": "Volkswagen",
"model": "Golf"
},
{
"quantity": 3,
"make": "Ford",
"model": "Escord"
},
{
"quantity": 2,
"make": "Opel",
"model": "Zafira"
}
]
I am looking to group by
the data based on the make
attribute and then identify the top three makes with the highest quantity. Any remaining makes will be categorized as "Other".
An example output I desire is:
var result = [
{
"brand": "Audi",
"count": 5
},
{
"brand": "Volkswagen",
"count": 3
},
{
"brand": "Ford",
"count": 3
},
{
"brand": "Other",
"count": 3
}
]
I'm seeking guidance on how to approach this task. Any suggestions?