function table.chunk(tbl, size) size = size or 1 size = size > 0 and size or 1 local result = {} local tblKeys = table.getKeys(tbl) for k, v in pairs(tblKeys) do local chunkId = math.ceil(k / size) if not result[chunkId] then result[chunkId] = {} end result[chunkId][v] = tbl[v] end return result end