I don't think (hope) this one is another of those thousands of trivial Array.sort questions (wrong data types basically).
So what I'm trying to do is:
[1, 3, 2, 7, 9, 4].sort((a, b) => a % 2 === 0 && b % 2 === 0 ? b - a : a - b)
that is, pairs of even numbers are to be ordered in descending order, the rest in ascending order as usual.
What I get is
[1, 2, 3, 4, 7, 9]
which is no surprise as only these pairs are compared:
[1, 3]
[3, 2]
[1, 2]
[3, 7]
[7, 9]
[9, 4]
[7, 4]
[3, 4]
So 2 and 4 are never compared to each other. Thus only one of my comparing rules is actually met in the result. What am I missing?
This is the result I'm expecting:
[1, 3, 4, 7, 9, 2]