Chapter III · The standard library / Lesson 16 of 27

Working with tables

You'll learn: Use table.insert, remove, sort, concat, and unpack to manipulate sequences.

table.insert(t, v) pushes; table.insert(t, pos, v) inserts at pos. table.remove(t) pops the tail. table.concat(t, sep) is the fast string-buffer pattern. table.sort(t[, cmp]) sorts in place. table.unpack(t) spreads a table back into a value list.

tables-stdlib.lua
Output idle
Hit Run to execute.
Try it: Sort {3, 1, 4, 1, 5, 9, 2, 6} so even numbers come before odd, and within each group ascending. Use a single comparator function.