FANDOM


m
m
Line 3: Line 3:
 
function p.removeDuplicates(frame)
 
function p.removeDuplicates(frame)
 
local arg, hash = frame:getParent().args[1], {}
 
local arg, hash = frame:getParent().args[1], {}
local m, n = mw.text.split(arg, ","), {}
+
local delimiter = args.delimiter or ","
  +
local m, n = mw.text.split(arg, delimiter), {}
   
 
for _, l in ipairs(m) do
 
for _, l in ipairs(m) do
Line 13: Line 13:
 
end
 
end
 
 
arg = table.concat(n, ",")
+
arg = table.concat(n, delimiter)
 
return arg
 
return arg
 
end
 
end
Line 19: Line 19:
 
function p.removeCustom(frame)
 
function p.removeCustom(frame)
 
local args, hash = frame:getParent().args, {}
 
local args, hash = frame:getParent().args, {}
local t = mw.text.split(args[1], ",")
+
local delimiter = args.delimiter or ","
local s = mw.text.split(args[2], ",")
+
local t = mw.text.split(args[1], delimiter)
  +
local s = mw.text.split(args[2], delimiter)
   
 
for i, v in ipairs(t) do
 
for i, v in ipairs(t) do
Line 27: Line 27:
 
end
 
end
   
if args[3] and not hash[args[3]] then return table.concat(t, ", ") end
+
if args[3] and not hash[args[3]] then return table.concat(t, delimiter) end
   
 
for i, v in ipairs(s) do
 
for i, v in ipairs(s) do
Line 40: Line 40:
 
end
 
end
 
end
 
end
return table.concat(t, ", ")
+
return table.concat(t, delimiter)
 
end
 
end
   

Revision as of 14:48, August 18, 2015

local p = {}
 
function p.removeDuplicates(frame)
	local arg, hash = frame:getParent().args[1], {}
	local delimiter = args.delimiter or ","
	local m, n = mw.text.split(arg, delimiter), {}
 
	for _, l in ipairs(m) do
	    l = mw.text.trim(l)
        if (not hash[l]) then
            n[#n+1] = l
            hash[l] = true
        end
    end
 
    arg = table.concat(n, delimiter)
	return arg
end
 
function p.removeCustom(frame)
	local args, hash = frame:getParent().args, {}
	local delimiter = args.delimiter or ","
	local t = mw.text.split(args[1], delimiter)
	local s = mw.text.split(args[2], delimiter)
 
    for i, v in ipairs(t) do
        t[i] = mw.text.trim(v)
        hash[t[i]] = true
    end
 
    if args[3] and not hash[args[3]] then return table.concat(t, delimiter) end
 
    for i, v in ipairs(s) do
        s[i] = mw.text.trim(v)
    end
 
	for j = #s, 1, -1 do
    	for i = #t, 1, -1 do
            if t[i] == s[j] then
                table.remove(t, i)
            end 
        end 
    end
    return table.concat(t, delimiter)
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.