I am trying to sort a list of characters first, followed by alphanumeric values. Here is what I have:
[Austria , Germany , 123aed , 234eds]
This is my current sorting attempt:
obj.sort((a,b) => {
if (
(isNaN(a.text) && isNaN(b.text)) || (!isNaN(a.text) && !isNaN(b.text))
) {
return a > b ? -1 : 1;
}
else {
return isNaN(a) ? -1 : 1;
}
})
However, the result is not as expected:
[123aed , 234eds , Austia , Germany]
Any advice or suggestions for improvement?