added functional.count_value to avoid a closure if you just want to count specific elements

This commit is contained in:
Max Cahill 2023-06-01 11:33:18 +10:00
parent ff2ab5f1aa
commit 4a93f41807

View File

@ -373,6 +373,17 @@ function functional.count(t, f)
return c
end
--counts the elements of t equal to v
function functional.count_value(t, v)
local c = 0
for i = 1, #t do
if t[i] == v then
c = c + 1
end
end
return c
end
--true if the table contains element e
function functional.contains(t, e)
for i = 1, #t do