Add table.count

This commit is contained in:
Simon Brodtmann 2025-04-06 16:43:21 +02:00
parent bbcc586128
commit 36dba7614e

View file

@ -92,4 +92,15 @@ function table.trim(target)
return table.filter(target, function(v)
return v ~= nil
end)
end
--- Counts the entries of given table.
--- @param target table Table to count
--- @return number Amount of entries
function table.count(target)
local count = 0
for _ in pairs(target) do
count = count + 1
end
return count
end