Module:Infobox sort: Difference between revisions
Appearance
Content deleted Content added
No edit summary |
No edit summary |
||
Line 27: | Line 27: | ||
end |
end |
||
table.sort( list, function (a, b) |
table.sort( list, function (a, b) |
||
indexA = a:find("%") |
indexA = a:find("%%") |
||
indexB = b:find("%") |
indexB = b:find("%%") |
||
numberA = tonumber(a:sub(1, indexA)) |
numberA = tonumber(a:sub(1, indexA)) |
||
numberB = tonumber(b:sub(1, indexB)) |
numberB = tonumber(b:sub(1, indexB)) |
Revision as of 11:48, 9 June 2020
local p = {}
function p.asc(frame)
list = {}
for key,value in pairs(frame.args) do
-- Remove newlines
stripped = string.gsub(value, "\n", "")
stripped = string.gsub(value, "\r", "")
if stripped ~= nil and stripped ~= "" and stripped ~= "\n" and stripped ~= " " and stripped ~= "\r" then
table.insert(list, stripped)
end
end
table.sort( list )
return table.concat( list, "<br>" )
end
function p.desc(frame)
list = {}
for key,value in pairs(frame.args) do
-- Remove newlines
stripped = string.gsub(value, "\n", "")
if stripped:match("%S") ~= nil then
table.insert(list, stripped)
end
end
table.sort( list, function (a, b)
indexA = a:find("%%")
indexB = b:find("%%")
numberA = tonumber(a:sub(1, indexA))
numberB = tonumber(b:sub(1, indexB))
return numberA > numberB
end )
return table.concat( list, "<br>" )
end
return p