When I want to sort an array, using sort() function , it is giving an alphabetically sorted array. Eg.
var a=[9,10,1];
a.sort();
I'm getting a = [1,10,9]
So, as per the suggestions I used another function
function sortfunction(x, y){
return (x - y) //causes an array to be sorted numerically and ascending
}
and then used
a.sort(sortfunction);
to get the right result.
Can anyone explain in detail, how this works?