I am working in a project and I want to rearrange objects based on its statuses. Basically, I want the objects with the "status" key that has the value "available" to appear at the top at the list, and the other objects with the "pending" or "sold" statuses to appear at the end.
I was trying to make the sort using this function:
let sortedProperties = properties.sort(function (a, b) {
return (
(a.status === "Available" ? 1 : 0) -
(b.status !== "Available" ? 1 : 0)
);
});
How can I make the sort work and push the objects that are not available to the bottom of the list?