Jump to content

Module:Sandbox/Jackmcbarn

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jackmcbarn (talk | contribs) at 01:59, 18 July 2014 (build name sorter). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

local function split(str, delim)
	local retval, endpos = {}, 1
	for elem, pos in str:gmatch('(.-)' .. delim .. '()') do
		table.insert(retval, elem)
		endpos = pos
	end
	table.insert(retval, str:sub(endpos))
	return retval
end

function p.main(frame)
	local list = mw.text.trim(frame.args[1])
	local listEntries = split(list, '\n')
	table.sort(listEntries, function(a,b)
		return split(a, ' ')[2]< split(b, ' ')[2]
	end)
	return table.concat(listEntries, '\n')
end

return p