What I'd expect with the next snippet to leave everything at it's index, but sort a specific item to the front:
const sorted = ["AUS", "GBR", "GER", "USA", "ZAF"].sort(code => code === "GBR" ? -1 : 0);
console.log(sorted);
Where I use just the first element, as I don't compare, just take care about if the first element is GBR
, place it to the front, otherwise, let it stay where it is now.
It works well on Chrome, but somehow Firefox leaves everything how it was originally. Or if I do ? -1 : 1
, it places GBR
to the front, but reverses the order of the rest of the items.
What am I doing wrong?