I currently have an array of objects stored in my database
[
{
price: "1"
type: "buy",
},
{
price: "2"
type: "buy",
},
{
price: "3"
type: "sell"
},
{
price: "4"
type: "sell"
}
]
What is the best way to aggregate this data in order to obtain an array of arrays containing all potential combinations (keeping in mind that the price can be any random number)
Filter out items with the highest buy price
and further organize them, so that items with the greatest price difference are positioned at the top
[
[
{
price: "1"
type: "buy",
},
{
price: "4"
type: "sell"
}
],
[
{
price: "1"
type: "buy",
},
{
price: "3"
type: "sell"
},
],
[
{
price: "2"
type: "buy",
},
{
price: "4"
type: "sell"
}
],
[
{
price: "2"
type: "buy",
},
{
price: "3"
type: "sell"
},
],
]