i need to sort my array. I'd like to see string starting/containing numbers after alfa.
As:
['ip', 'email', '0email', 'em0ail' ,1001, '23name', 'name', 'address']
should be:
['address', 'email', 'em0ail', 'ip', 'name', '0email', 1001, '23name']
So 0 should be after z
columns.sort((a, b) => {
const x = a.toString();
const y = b.toString();
if (x < y) {
return -1;
}
if (x > y) {
return 1;
}
return 0;
});
returns numbers first
How should i approach this case? Do i have to iterate through whole string?