Difference between revisions of "Module:TableTools"
Jump to navigation
Jump to search
fix the valueUnion function for NaNs (and make it a lot simpler to boot)
>Mr. Stradivarius (remove shallowClone - hardly worth having this in here) |
>Mr. Stradivarius (fix the valueUnion function for NaNs (and make it a lot simpler to boot)) |
||
Line 17: | Line 17: | ||
local infinity = math.huge | local infinity = math.huge | ||
local checkType = libraryUtil.checkType | local checkType = libraryUtil.checkType | ||
--[[ | --[[ | ||
Line 140: | Line 137: | ||
function p.valueUnion(...) | function p.valueUnion(...) | ||
local lim = select('#', ...) | local lim = select('#', ...) | ||
if lim | if lim < 2 then | ||
error(" | error(lim .. ' argument' .. (lim == 1 and '' or 's') .. " passed to 'valueUnion' (minimum is 2)", 2) | ||
end | end | ||
local | local isNan = p.isNan | ||
local ret, exists = {}, {} | |||
for i = 1, lim do | for i = 1, lim do | ||
local t = select(i, ...) | local t = select(i, ...) | ||
checkType('valueUnion', i, t, 'table') | checkType('valueUnion', i, t, 'table') | ||
for k, v in pairs(t) do | for k, v in pairs(t) do | ||
if | if isNan(v) then | ||
v = | ret[#ret + 1] = v | ||
elseif not exists[v] then | |||
ret[#ret + 1] = v | |||
exists[v] = true | |||
end | end | ||
end | end | ||
end | end | ||
return ret | return ret |