I've seen similar questions. But I'm trying to do a partial sort of an array based on values from another array.
Here is what I'm looking for:
let array = [
{
name: "Foo",
values: [a, b, c, d]
},
{
name: "Bar",
values: [x, y]
},
{
name: "FooBar",
values: [k, l, m]
},
{
name: "BarBar",
values: [m, n]
}
]
and
let sort = ["BarBar", "Bar"]
and the desired output is:
let desiredOutput = [
{
name: "BarBar",
values: [m, n]
},
{
name: "Bar",
values: [x, y]
},
{
name: "Foo",
values: [a, b, c, d]
},
{
name: "FooBar",
values: [k, l, m]
}
]
Array is sorted based on only two values and every other elements follow the same order.
I'm wondering if it is possible to achieve this.