Syntax
sort(array)
rsort(array)
Description
The sort() function returns a new array sorted in ascending order.
The rsort() function returns a new array sorted in descending order.
Example
a=[5,4,3,2,1] b=sort(a) println(a,"\n", b) [5, 4, 3, 2, 1] [1, 2, 3, 4, 5]
sort() is unable to manage mixed data with much intelligence, so results will often cause confusion, anger, and has sometimes been known to induce alcohol consumption.
Further Examples
a=[2.1, 4, 3, 1.1, 1] b=[1.2, 2.2, 3, 1] c=[1, 2.1, 3, 4.2, "norbert"] println("a=", sort(a)) println("b=", sort(b)) println("c=", sort(c)) println("a=", rsort(a)) println("b=", rsort(b)) println("c=", rsort(c)) a=[1, 1.1, 3, 4, 2.1] b=[1, 3, 1.2, 2.2] c=[2.1, 4.2, 1, 3, "norbert"] a=[2.1, 4, 3, 1.1, 1] b=[2.2, 1.2, 3, 1] c=["norbert", 3, 1, 4.2, 2.1]
If you need to sort a mixture of integers and floating point numbers, then
you may want to do:
a=[1, 1.1, 3, 4, 2.1] println(sort(float(a))) println(rsort(float(a))) [1, 1.1, 2.1, 3, 4] [4, 3, 2.1, 1.1, 1]
Which will covert the contents of the array to floating point numbers prior to a sort.
This function is still in flux and if enough alcohol is consumed, I may fix the integer/float thingy.