Module:TableTools: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
add a key/value pair intersection function
(add key/value pair union function)
(add a key/value pair intersection function)
Line 107:
------------------------------------------------------------------------------------
--]]
function p.intersection(...)
local differentVals = {} -- A substitute variable to use when we have different values for the same key.
local ret, track, pairCounts = {}, {}, {}
local lim = select('#', ...)
for i = 1, lim do
local t = select(i, ...)
for k, v in pairs(t) do
local trackVal = track[k]
if trackVal == nil then
track[k] = v
pairCounts[k] = 1
elseif trackVal == v then
pairCounts[k] = pairCounts[k] + 1
end
end
end
for k, v in pairs(track) do
if pairCounts[k] == lim then
ret[k] = v
end
end
return ret
end
 
--[[
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu