Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Remove Duplicate Links

From the Star Citizen Wiki, the fidelity™ encyclopedia
Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:Remove Duplicate Links/doc. Changes can be proposed in the talk page.
Function list
L 4 — p.main

local p = {}

--- Remove duplicate links and return the singular ones
function p.main(frame)
    local input = frame.args[1] or ""

    local links = {}
    input:gsub("%[%[([^%]]*)%]%]", function(link)
        link = "[[" .. link .. "]]" -- :gsub removes the double brackets
        table.insert(links, link)
    end)

    local duplicateTracker = {}
    for _, link in pairs(links) do
        if not duplicateTracker[link] then
            duplicateTracker[link] = 0
        end
        duplicateTracker[link] = duplicateTracker[link] + 1
    end

    local output = ""
    for link, duplicates in pairs(duplicateTracker) do
        if duplicates == 1 then
            output = output .. link
        end
    end

    return output
end

return p
Heya! We only use cookie to make the site function and save your preferences, nothing else :)