Jump to content

Module:Sort list: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Undid revision 714802176 by Frietjes (talk)
use lambda for revcomp
Line 9: Line 9:
function p.desc(frame)
function p.desc(frame)
items = splitLine( frame.args[1] );
items = splitLine( frame.args[1] );
table.sort( items, revComp );
table.sort( items, function (a, b) return a > b end );
return table.concat( items, "\n" );
return table.concat( items, "\n" );
end
end
Line 17: Line 17:
end
end



function revComp( a, b )
return a > b;
end


return p
return p

Revision as of 00:50, 13 April 2016

local p = {}

function p.asc(frame)
    items = splitLine( frame.args[1] );
    table.sort( items );
    return table.concat( items, "\n" );    
end

function p.desc(frame)
    items = splitLine( frame.args[1] );
    table.sort( items, function (a, b) return a > b end );
    return table.concat( items, "\n" );
end

function splitLine( text )
    return mw.text.split( text, "\n", true );    
end



return p