|
DanteX Apprentice
Joined: 13 Aug 2007 Posts: 166
|
Posted: Sun Aug 26, 2007 6:10 pm
[2.01] %sort not sorting in numerical order |
This piece of code gives me this output:
Code: |
#ALIAS testalias($number) {
$FirstAmmount=0
$SecondAmmount=0
$ThirdAmmount=0
$first=0
$second=0
$third=0
#LOOP $number {
TestArray=""
$time=%secs
#LOOP 10000 {#IF (@test) {} {}}
$first=( %secs-$time)
#SHOW FIRST: $first
$time=%secs
#LOOP 10000 {#IF (%DB( @testvar, test)) {} {}}
$second=( %secs-$time)
#SHOW SECOND: $second
$time=%secs
#LOOP 10000 {#IF (@testvar.test) {} {}}
$third=( %secs-$time)
#SHOW THIRD: $third
#ADDITEM TestArray $first
#ADDITEM TestArray $second
#ADDITEM TestArray $third
#SHOW TestArray @TestArray
#SHOW SortedTestArray: %sort(@TestArray)
}
} |
gives me this output
FIRST: 141
SECOND: 1203
THIRD: 938
TestArray 141|1203|938
SortedTestArray: 1203|141|938
The %sort function doesn't sort array in numerical order, but alphabetical.
D |
|
|
|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Sun Aug 26, 2007 6:31 pm Re: [2.01] %sort not sorting in numerical order |
DanteX wrote: |
The %sort function doesn't sort array in numerical order, but alphabetical. |
I think that is intended.
From the help files:
"Syntax: %sort(list,dir)
returns the list with items sorted in alphabetical order. If dir is missing or zero, list is sorted in ascending order. If dir is non-zero, list is sorted in descending order. " |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Mon Aug 27, 2007 1:44 am |
Yes, it is intentional, and that's why you need to prepend numbers with zeros and pad it out as a fixed-length string. Would be nice to have an option on %sort to sort numerically, now that we can have more specifically typed variables.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Aug 27, 2007 6:53 pm |
I'll add this to the wish list to see if I can come up with a way to add an optional argument to %sort.
Just remember that these are *not* "arrays"...they are *string* lists. That means that each value in the list is a *string* value. |
|
|
|
|
|