Quote:
Originally Posted by xXziroXx
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.i = 0; temp.i < 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.)