Sorting an array in Sage X3
To sort an array use Sorta with the following syntax:
SORTA NUMVALUE_ToORDER ARRAY [Desc]
SORTA NUMVALUE_ToORDER ARRAY1, array2 [Desc]
(array2 ordered following the order of ARRAY1)
Example:
Local Char STR(255)(0..4) Local Integer NUMBER(0..4) Local Integer D NUMBER(0) = 3 NUMBER(1) = 4 NUMBER(2) = 9 NUMBER(3) = 5 NUMBER(4) = 8 STR(0) = "B" STR(1) = "E" STR(2) = "C" STR(3) = "M" STR(4) = "A" D= dim(NUMBER)
To sort NUMBER in ascending order, and strings based on NUMBER numbers
Sorta D NUMBER,STR #final results: NUMBER(0) = 3 NUMBER(1) = 4 NUMBER(2) = 5 NUMBER(3) = 8 NUMBER(4) = 9 STR(0) = "B" STR(1) = "E" STR(2) = "M" STR(3) = "A" STR(4) = "C"
To sort the first 4 strings in alphabetical order
Sorta 4 STR
To sort the first 4 strings in alphabetical order, and the numbers based on string order
Sorta 4 STR,NUMBER
To sort in descending order
Sorta D STR, NUMBER Desc
I hope you have been useful!