View Single Post
  #3  
Old 01-07-2011, 11:32 PM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by xXziroXx View Post
You basically assign a value to each entry adn sort by value.
Uh, this works for sortascending? I thought it was for GUIs.


The problem is that it is sorting by the string value, rather than the number value.
i.e.,
{"aaa", "aab", "ba", "c"} is sorted by the string value.
{111, 112, 21, 3} is sorted by the string value, when it should really be sorted by float value into: {3,21,111,112}.


To my knowledge there are two ways to solve this:

Way 1
Store the number in a subvariable for each item in the array, then use sortbyvalue:
PHP Code:
temp.xs = {1,6,7,3,2,1,5,23,41,75,2347,51,123};

for (
temp.0temp.temp.xs.size(); temp.i++) {
  
temp.xs[temp.i].blah temp.xs[temp.i];
}
temp.xs.sortbyvalue("blah""float"true); 
Way 2
Use quicksort, which lets you specify your own function for comparing two values. (See examples in the link.)
Reply With Quote