Jump to content

Module:TableTools: Difference between revisions

add getUnion function
m>Mr. Stradivarius
(add a fancy introductory comment)
m>Mr. Stradivarius
(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


--[[
--[[
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.