grouping elements of array

I have a array as follows :

data = [
{
 "type":"abc",
 "quantity":36,
 "code:"EDF"
},
{
 "type":"abc",
 "quantity":40
 "code:"SFDF"
},
{
 "type":"yrf",
 "quantity":22
 "code:"SFDF"
},
{
 "type":"yrf",
 "quantity":19
 "code:"EDF"
}
]

I want to group elements of this array on the basis of type and code. for example, if type is “abc”, then I want to include new attributes for quantity of EDF as “quantity_EDF”,and quantity of SFDF as “quantity_SFDF”. So my resultant array will look as follows:

resultantArray = [
{
"type":"abc",
"quantity_EDF":36,
"quantity_SFDF":40
},
{
"type":"yrf",
"quantity_EDF":19,
"quantity_SFDF":22
}
]

How can I do this?