mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-22 14:14:36 +00:00
[added] tablex.trim to trim a table to a certain length
This commit is contained in:
parent
028b21ef9a
commit
5f124be2f0
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user