View Single Post
Old Jun 25th, 2005, 12:26 PM   #2
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Firstly: why are you using a JavaScript-coded sort function? It will be 100s of times slower than the sort function provided by to the JavaScript interpreter via Array.sort().

It's sorting alphabetically in ASCII, not by integer value (I would have thought the function name, 'sortAsc', would have been a clue here). The JavaScript Array.sort function also does the same, but you can pass it a function as a parameter that will be used in evaluating how to sort the list.
So, to sort a bunch of numbers:
var nums = new Array(32, 23, 5, 49, 82, 245, 5, 1);
nums.sort(function(a, b) { return a - b; });
// nums is now sorted.
Cerulean is offline   Reply With Quote