[added] tablex.trim to trim a table to a certain length

This commit is contained in:
Max Cahill 2020-08-24 20:54:43 +10:00
parent 028b21ef9a
commit 5f124be2f0

View File

@ -152,6 +152,14 @@ function tablex.reverse(t)
return t
end
--trim a table to a certain maximum length
function tablex.trim(t, l)
while #t > l do
table.remove(t)
end
return t
end
--collect all keys of a table into a sequential table
--(useful if you need to iterate non-changing keys often and want an nyi tradeoff;
-- this call will be slow but then following iterations can use ipairs)