mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-25 15:14:35 +00:00
added functional.count_value to avoid a closure if you just want to count specific elements
This commit is contained in:
parent
ff2ab5f1aa
commit
4a93f41807
@ -373,6 +373,17 @@ function functional.count(t, f)
|
|||||||
return c
|
return c
|
||||||
end
|
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
|
--true if the table contains element e
|
||||||
function functional.contains(t, e)
|
function functional.contains(t, e)
|
||||||
for i = 1, #t do
|
for i = 1, #t do
|
||||||
|
Loading…
Reference in New Issue
Block a user