From bd7573b4578dc3134dbdd91f4d7c6a89ad3803c7 Mon Sep 17 00:00:00 2001 From: notnotmelon Date: Mon, 17 Jun 2024 09:29:18 -0500 Subject: [PATCH] update table lib with new function --- lib/table.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/table.lua b/lib/table.lua index d0fa6e9..0883030 100644 --- a/lib/table.lua +++ b/lib/table.lua @@ -104,6 +104,15 @@ end ---@param tbl table ---@return any table.last = function(tbl) + local result + for _, v in pairs(tbl) do result = v end + return result +end + +---Returns the last element of the array. +---@param tbl any[] +---@return any +table.array_last = function(tbl) local size = #tbl if size == 0 then return nil end return tbl[size]