I have an array of objects, each object has a "condition" property. It can either be a single value string ex "Original"
, or a multiple comma separated values string ex "Original, Brand new"
. i see this question also , but in that not tell about sort for given order
[
{id: 1, condition: "Original"},
{id: 2, condition: "Original, Used"},
{id: 3, condition: "Used"},
{id: 4, condition: "After market"},
{id: 5, condition: "After Market,Used"},
{id: 6, condition: "Used"},
{id: 7, condition: "Used, Original"},
]
I want to sort my array based on the "condition" property and the sort function should accept an argument being an array of keys to ask for a specific order:
Given the following keys as input ["Original","Used","After Market"]
,
the sort function would return this array:
[
{id: 1, condition: "Original"},
{id: 2, condition: "Original, Used"},
{id: 7, condition: "Used, Original"}
{id: 3, condition: "Used"},
{id: 6, condition: "Used"},
{id: 5, condition: "After Market,Used"},
{id: 4, condition: "After market"},
]