Module:Sort
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Sort/doc
local p = {}
-- This separates words by ", ". It seems more usefull than the version I found on wiki.
function p.asc(frame)
items = splitLine( frame.args[1] );
table.sort( items );
return table.concat( items, ", " );
end
function p.des(frame)
items = splitLine( frame.args[1] );
table.sort( items, function (a, b) return a > b end );
return table.concat( items, ", " );
end
function splitLine( text )
return mw.text.split( text, ", ", true );
end
-- This is a version that separates words by line breaks ("\n") as originally on wikipedia.
-- Left in case it is relevant for some use-case.
function p.asc2(frame)
items = splitLine2( frame.args[1] );
table.sort( items );
return table.concat( items, "\n" );
end
function p.des2(frame)
items = splitLine2( frame.args[1] );
table.sort( items, function (a, b) return a > b end );
return table.concat( items, "\n" );
end
function splitLine2( text )
return mw.text.split( text, "\n", true );
end
return p