From 5f124be2f09357a3b3d67f96ecee1db5f0234c17 Mon Sep 17 00:00:00 2001 From: Max Cahill <1bardesign@gmail.com> Date: Mon, 24 Aug 2020 20:54:43 +1000 Subject: [PATCH] [added] tablex.trim to trim a table to a certain length --- tablex.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tablex.lua b/tablex.lua index b80797e..5f38da2 100644 --- a/tablex.lua +++ b/tablex.lua @@ -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)