I have a following data JSON data which I have to group by priority then organise the grouped data in order where first two result will be type 1 and next 1 of type 2 and next 1 will be type 3 and then repeat
{
"list": [{
"_id": "555ed01e0f398a7b1436bf05",
"type": 1,
"priority": 1,
"name": "John"
},
{
"_id": "555ed01e0f398a7b1436bf07",
"type": 2,
"priority": 1,
"name": "Jack"
},
{
"_id": "555ed01e0f398a7b1436bf09",
"type": 1,
"priority": 1,
"name": "Smith"
},
{
"_id": "555ed01e0f398a7b1436bf09",
"type": 2,
"priority": 1,
"name": "Kiles"
},
{
"_id": "555ed01e0f398a7b1436bf11",
"type": 1,
"priority": 1,
"name": "Stacy"
},
{
"_id": "555ed01e0f398a7b1436bf13",
"type": 1,
"priority": 2,
"name": "Stacy"
}
]
}
I am trying to do this by using lodash
_.chain(myArray).groupBy("priority").map(item=> _.groupBy(item,"offerType")).value()
This give me grouped and sorted result accordingly but now I am stuck with custom ordering in the results. How to achieve the desired order in list.
The result I am looking for
{
"list": [{
"_id": "555ed01e0f398a7b1436bf05",
"type": 1,
"priority": 1,
"name": "John"
},
{
"_id": "555ed01e0f398a7b1436bf09",
"type": 1,
"priority": 1,
"name": "Smith"
},
{
"_id": "555ed01e0f398a7b1436bf07",
"type": 2,
"priority": 1,
"name": "Jack"
},
{
"_id": "555ed01e0f398a7b1436bf11",
"type": 1,
"priority": 1,
"name": "Stacy"
},
{
"_id": "555ed01e0f398a7b1436bf09",
"type": 2,
"priority": 1,
"name": "Kiles"
},
{
"_id": "555ed01e0f398a7b1436bf13",
"type": 2,
"priority": 2,
"name": "Stacy"
}
]
}