I'm getting an array back from an URL which looks like this:
[
{
id : 1,
product_id : 101,
price_new : 80,
price_old : 90
},
{
id : 2,
product_id : 101,
price_new : 80,
price_old : 90
},
{
id : 3,
product_id : 102,
price_new : 80,
price_old : 90
},
]
I would like to transform this, to:
[
{
product_id : 101,
offers : [
{
id: 1
price_new : 80,
price_old : 90
},{
id: 2
price_new : 80,
price_old : 90
}]
},
{
product_id : 102,
offers: [{
id : 3,
price_new : 80,
price_old : 90
}]
},
]
Anyone who knows how to get this done using underscore js? Would love to get a solution using underscore cause we're using it in our entire project and it looks more clean, so...