So, I have a sorting method designed to sort the values alphabetically, which works fine in almost all cases:
function alphabetical(name1, name2):int {
if (name1 < name2){
return -1;
} else if (name1 > name2){
return 1;
}else {
return 0;
};
};
The problem is that when the header contains a number in it.
For instance:
['abc 8','abc 1','abc 10']
will be sorted into
['abc 1','abc 10','abc 8']
but I need it to be sorted in alphabetical order, but when it encounters a number, the numeric value is taken into account, and so sorting returns
['abc 1','abc 8'.'abc 10']
I was hoping there would be some existing regular expression or algorithms for this, but I'm afraid that I don't know what to look for. All my sort searches are done in alphabetical or digital form, and not both.
Many thanks!
source
share