Table.sort

From GiderosMobile
Revision as of 10:02, 23 August 2018 by Hgy29 (talk | contribs) (Created page with "__NOTOC__ '''Available since:''' Gideros 2011.6<br/> === Description === Sort the elements of a table in-place (i.e. alter the table). `> t = { 3,2,5,1,4 }` `> table.sort(t)`...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Available since: Gideros 2011.6

Description

Sort the elements of a table in-place (i.e. alter the table). `> t = { 3,2,5,1,4 }` `> table.sort(t)` `> = table.concat(t, ", ") -- display sorted values` `1, 2, 3, 4, 5`

A comparison function can be provided to customise the element sorting. The comparison function must return a boolean value specifying whether the first argument should be before the second argument in the sequence. The default behaviour is for the < comparison to be made. For example, the following behaves the same as no function being supplied:

= table.sort(tablecomp,)

'table: (table) table to sort '
comp: (function) comparison function returning bool comparison result optional