Difference between revisions of "Module:TableTools"

45 bytes added ,  23:46, 19 December 2013
only allow two or more arguments for the set functions
>Mr. Stradivarius
(add type-checking to removeDuplicates)
>Mr. Stradivarius
(only allow two or more arguments for the set functions)
Line 92: Line 92:
function p.union(...)
function p.union(...)
local lim = select('#', ...)  
local lim = select('#', ...)  
if lim == 0 then
if lim < 2 then
error("no arguments passed to 'union'", 2)
error(lim .. ' argument' .. (lim == 1 and '' or 's') .. " passed to 'union' (minimum is 2)", 2)
end
end
local ret, trackArrays = {}, {}
local ret, trackArrays = {}, {}
Line 168: Line 168:
function p.intersection(...)
function p.intersection(...)
local lim = select('#', ...)  
local lim = select('#', ...)  
if lim == 0 then
if lim < 2 then
error("no arguments passed to 'intersection'", 2)
error(lim .. ' argument' .. (lim == 1 and '' or 's') .. " passed to 'intersection' (minimum is 2)", 2)
end
end
local ret, track, pairCounts = {}, {}, {}
local ret, track, pairCounts = {}, {}, {}
Line 254: Line 254:
function p.complement(...)
function p.complement(...)
local lim = select('#', ...)  
local lim = select('#', ...)  
if lim == 0 then
if lim < 2 then
error("no arguments passed to 'complement' (minimum is two)", 2)
error(lim .. ' argument' .. (lim == 1 and '' or 's') .. " passed to 'complement' (minimum is 2)", 2)
elseif lim == 1 then
error("only one argument passed to 'complement' (minimum is two)", 2)
end
end
--[[
--[[
Anonymous user