Module:TableTools: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
add getUnion function
(add a fancy introductory comment)
(add getUnion function)
Line 32:
end
end
 
--[[
------------------------------------------------------------------------------------
-- getUnion
--
-- This returns the union of the values of n tables, as an array. For example, for
-- the tables {1, 3, 4, 5, foo = 7} and {2, 3, 5, bar = 6}, getUnion will return
-- {1, 2, 3, 4, 5, 6, 7}.
------------------------------------------------------------------------------------
--]]
function p.getUnion(...)
local arrays = {...}
local vals, ret = {}, {}
for _, t in ipairs(arrays) do
for k, v in pairs(t) do
vals[v] = true
end
end
for val in pairs(vals) do
ret[#ret + 1] = val
end
table.sort(ret)
end
 
--[[
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu