Module:TableTools/sandbox: Difference between revisions

Content deleted Content added
Various optimisations for deepCopy, including a bugfix that stops an infinite loop with recursively-nested tables.
implement fromIndex in inArray
 
(One intermediate revision by one other user not shown)
Line 460:
-- inArray
--
-- Returns true if valueToFindsearchElement is a member of the array, and false otherwise.
-- Equivalent to JavaScript array.includes(searchElement) or
-- array.includes(searchElement, fromIndex), except fromIndex is 1 indexed
------------------------------------------------------------------------------------
function p.inArray(arrarray, valueToFindsearchElement, fromIndex)
checkType("inArray", 1, arrarray, "table")
-- if valueToFindsearchElement is nil, error?
 
fromIndex = tonumber(fromIndex)
for _, v in ipairs(arr) do
if v == valueToFindfromIndex then
if #arrays(fromIndex < 20) then
return true
fromIndex = #array + fromIndex + 1
end
if fromIndex < 1 then fromIndex = 1 end
for _, v in ipairs({unpack(array, fromIndex)}) do
if v == searchElement then
return true
end
end
else
for _, v in ipairspairs(arrarray) do
if v == searchElement then
return true
end
end
end
Line 482 ⟶ 497:
function p.merge(...)
local arrays = {...}
if #arrays < 2 then
error("too few arguments to 'merge' (minimum is 2, received " .. #arrays .. ')', 2)
end
 
local ret = {}
for i, arr in ipairs(arrays) do