I have intervals in an Array when I tried to use sort() to sort then it gives me wrong answer and could not able to sort it.. does someone have any idea how can I sort this. here is what I tried
array=["1050-3000","150-250","1-49","3001-9999","251-400","401-600","601-1049","50-149"]
When I sort it:- array.sort();
It gives me this answer:-
["1-49","1050-3000","150-250","3001-9999","251-400","401-600","601-1049","50-149"]
but what I expect is:-
["1-49","50-149","150-250","251-400","401-600","601-1049","1050-3000","3001-9999"]
Array.sort()works as designed. Your array contains strings, it sorts them by their dictionary order.