Skip to content

Commit a0b2f7a

Browse files
committed
refactor(table.shared): contains value can by a table and watch multiple values
1 parent 0a56189 commit a0b2f7a

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

imports/table/shared.lua

+20-6
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,29 @@ local function Clone(t)
2020
return target
2121
end
2222

23-
--- supv.table.contains - Check if a table contains a value
23+
--- supv.table.contains - Check if a table contains a value(s)
2424
---@param t table
2525
---@param value any
2626
---@return boolean
27-
local function Contains(t, value)
28-
for _, v in pairs(t)do
29-
if v == value then return true end
30-
end
31-
return false
27+
local function Contains(tbl, value)
28+
if type(value) ~= 'table' then
29+
for _, v in pairs(tbl) do
30+
if v == value then return true end
31+
end
32+
else
33+
local matched_values = 0
34+
local values = 0
35+
for _, v1 in pairs(value) do
36+
values += 1
37+
38+
for _, v2 in pairs(tbl) do
39+
if v1 == v2 then matched_values += 1 end
40+
end
41+
end
42+
if matched_values == values then return true end
43+
end
44+
45+
return false
3246
end
3347

3448
local function toVec3(coords)

0 commit comments

Comments
 (0)