Difference between revisions of "Module:SortList"

From Blaseball Wiki

m
Tag: 2017 source edit
m
Tag: 2017 source edit
Line 6: Line 6:
 
     return table.concat( items, "\n\n" );     
 
     return table.concat( items, "\n\n" );     
 
end
 
end
 
 
function p.desc(frame)
 
function p.desc(frame)
 
     items = splitLine( frame.args[1] );
 
     items = splitLine( frame.args[1] );
 
     table.sort( items, function (a, b) return a >= b end );
 
     table.sort( items, function (a, b) return a >= b end );
 +
    return table.concat( items, "\n\n" );
 +
end
 +
 +
function p.reverse(frame)
 +
    items = splitLine( frame.args[1] );
 +
    local n = #items
 +
    local i = 1
 +
    while i < n do
 +
        items[i],items[n] = items[n],items[i]
 +
        i = i + 1
 +
        n = n - 1
 +
    end
 
     return table.concat( items, "\n\n" );
 
     return table.concat( items, "\n\n" );
 
end
 
end
  
 
function splitLine( text )
 
function splitLine( text )
     return mw.text.split( text, "°", true );  
+
     return mw.text.split( text, "°", true );
 
end
 
end
  

Revision as of 01:53, 6 October 2020

local p = {}

function p.asc(frame)

   items = splitLine( frame.args[1] );
   table.sort( items );
   return table.concat( items, "\n\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\n" );

end

function p.reverse(frame)

   items = splitLine( frame.args[1] );
   local n = #items
   local i = 1
   while i < n do
       items[i],items[n] = items[n],items[i]
       i = i + 1
       n = n - 1
   end
   return table.concat( items, "\n\n" );

end

function splitLine( text )

   return mw.text.split( text, "°", true );

end


return p