Module:Utils: Difference between revisions

Move table_contains to top and rework on it
Fredg999 (talk | contribs)
Add index_of function
Line 2: Line 2:
local p = {}
local p = {}
-- Check if a table contains x
-- check if a table contains x
function p.table_contains(tbl, x)
function p.table_contains(tbl, x)
     for i = 1, #tbl do
     for i = 1, #tbl do
Line 10: Line 10:
     end
     end
     return false
     return false
end
-- return the first index with the given value (or nil if not found)
function index_of(array, value)
for i, v in ipairs(array) do
if v == value then
return i
end
end
return nil
end
end