So I have a sort method designed to sort values alphabetically which works great 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 though, when a title contains a number in it.
For example:
['abc 8','abc 1','abc 10']
would sort to
['abc 1','abc 10','abc 8']
but what I need to happen is for it to sort alphabetically but when it encounters a number a numeric value is taken into consideration and thus the sorting would return
['abc 1','abc 8'.'abc 10']
I was hoping there was some sort of existing regex or algorithms built to do this but I am afraid I haven't the slightest clue what to search for. All my searches for sorting either does it alphabetically or numerically, not both.
thanks so much!