PDA

View Full Version : Sorting arrays


Chandler
01-21-2007, 07:17 PM
sortascending() - sorts the array in ascending order (smallest value first)

sortbyvalue(str, str, bool) - sorts the array by the specified variable name, you must also say what variable type it is (e.g. string) and if it should be sorted ascending

sortdescending() - sorts the array in descending order (highest value first)

Has anyone else managed to get these to work?

xXziroXx
01-21-2007, 08:19 PM
Im pretty sure Ive used sortascending() and sortdescending() in the past, and they've worked.

Riot
01-21-2007, 10:10 PM
sortbyvalue works as well:


function onCreated()
{
this.array = null;
addn("B");
addn("C");
addn("D");
addn("A");

echo(this.array[0].name);
this.array.sortbyvalue("name", "string", false);
echo(this.array[0].name);
this.array.sortbyvalue("name", "string", true);
echo(this.array[0].name);
}

function addn(n)
{
temp.data = new TStaticVar(@temp.n);
temp.data.somevar = "test";

this.array.add(temp.data);
}


outputs:
B (default)
D (descending)
A (ascending)