From 4a93f41807306945fb4b209fb77c70392c14355b Mon Sep 17 00:00:00 2001 From: Max Cahill <1bardesign@gmail.com> Date: Thu, 1 Jun 2023 11:33:18 +1000 Subject: [PATCH] added functional.count_value to avoid a closure if you just want to count specific elements --- functional.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/functional.lua b/functional.lua index 3dabcc2..1b2d67e 100644 --- a/functional.lua +++ b/functional.lua @@ -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