Module:Infobox sort: Difference between revisions
Appearance
Content deleted Content added
Make asc function similarly to desc |
Added some newlines for readability |
||
Line 3: | Line 3: | ||
function p.asc(frame) |
function p.asc(frame) |
||
list = {} |
list = {} |
||
for key,value in pairs(frame.args) do |
for key,value in pairs(frame.args) do |
||
-- Remove newlines |
-- Remove newlines |
||
Line 11: | Line 12: | ||
end |
end |
||
end |
end |
||
table.sort( list, function (a, b) |
table.sort( list, function (a, b) |
||
indexA = a:find("%%") |
indexA = a:find("%%") |
||
Line 18: | Line 20: | ||
return numberA < numberB |
return numberA < numberB |
||
end ) |
end ) |
||
return table.concat( list, "<br>" ) |
return table.concat( list, "<br>" ) |
||
end |
end |
||
Line 23: | Line 26: | ||
function p.desc(frame) |
function p.desc(frame) |
||
list = {} |
list = {} |
||
for key,value in pairs(frame.args) do |
for key,value in pairs(frame.args) do |
||
-- Remove newlines |
-- Remove newlines |
||
Line 31: | Line 35: | ||
end |
end |
||
end |
end |
||
table.sort( list, function (a, b) |
table.sort( list, function (a, b) |
||
indexA = a:find("%%") |
indexA = a:find("%%") |
||
Line 38: | Line 43: | ||
return numberA > numberB |
return numberA > numberB |
||
end ) |
end ) |
||
return table.concat( list, "<br>" ) |
return table.concat( list, "<br>" ) |
||
end |
end |
Revision as of 12:02, 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", "")
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 - 1))
numberB = tonumber(b:sub(1, indexB - 1))
return numberA < numberB
end )
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 - 1))
numberB = tonumber(b:sub(1, indexB - 1))
return numberA > numberB
end )
return table.concat( list, "<br>" )
end
return p