RosettaCodeData/Task/Sort-an-integer-array/M2000-Interpreter/sort-an-integer-array.m2000

22 lines
618 B
Plaintext

module Sort_an_integer_array{
const n=10
// s() for feeding array
s=lambda n=1 (x)->{=x-n:n++}
dim a(1 to n) as long long<<s(n)
print a()#str$()
sort a()
print a()#str$()="0 1 2 3 4 5 6 7 8 9"
' sort a copy - indexing from 0
' -1 for descending
print a()#slice(0, 4)#sort(-1)#str$()="4 3 2 1 0"
dim b() as long long
b()=a()#slice(0, 4)#sort(-1)
print b(0)=4, type$(b(0))="Long Long"
dim b(1 to 5) ' change base from 0 to 1
print b(1)=4, type$(b(1))="Long Long"
dim b(1 to 6) ' resize preserving
print b(6)=0, type$(b(6))="Long Long"
Print b()#str$(", ")="4, 3, 2, 1, 0, 0"
}
Sort_an_integer_array