HyperMath

Sorting

Sorting

Previous topic Next topic No expanding text in this topic  

Sorting

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

table.sort(t)

Sorts the elements of a table in-place in ascending order to alter the table.

> t = { 3,2,5,1,4 }

> table.sort(t)

> print(t[1],t[2],t[3],t[4],t[5])  // display sorted values

1        2        3        4        5

> t ={"xyz", "abc", "axy", "Abc"}

> table.sort(t)

> print(t[1],t[2],t[3],t[4])

Abc        abc        axy        xyz

All table entries must be of the same type.  For example, strings and numbers cannot be sorted in a mix.