Pergi ke kandungan

Modul:table/reverse

Daripada Wikikamus
local table_length_module = "Module:table/length"

local function table_len(...)
	table_len = require(table_length_module)
	return table_len(...)
end

--[==[
Takes a list, and returns a new list with the values in the reverse order: { { "a", "b", "c" }} -> { { "c", "b", "a" }}.]==]
return function(t)
	local list, t_len = {}, table_len(t)
	for i = 1, t_len do
		list[i] = t[t_len - i + 1]
	end
	return list
end