Module:TableTools: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
621 bytes added ,  15 December 2013
add getUnion function
(add a fancy introductory comment)
(add getUnion function)
Line 32: Line 32:
end
end
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.