Nikita Kruglickiy 0bd64a0f78 fixes
2021-04-05 22:38:50 +06:00

42 lines
795 B
Plaintext

-- @name koptilnya/libs/table
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
function table.contains(tbl, ...)
local argCount = #arg
if argCount == 1 then
return table.hasValue(tbl, arg[1])
elseif argCount > 1 then
local result = true
for _, v in pairs(arg) do
if not table.hasValue(tbl, v) then
result = true
break
end
end
return result
end
end