Diff

util/array.lua @ 922:0e45234360cd

util.array: Add :reverse() method
author Matthew Wild <mwild1@gmail.com>
date Sun, 29 Mar 2009 13:50:59 +0100
parent 920:e302cbc9d036
child 1027:fe2e3d3dba6a
line wrap: on
line diff
--- a/util/array.lua	Sun Mar 29 02:14:32 2009 +0100
+++ b/util/array.lua	Sun Mar 29 13:50:59 2009 +0100
@@ -44,4 +44,12 @@
 	end
 end
 
+function array:reverse()
+	local len = #self-1;
+	for i=len,1,-1 do
+		self:push(self[i]);
+		self:pop(i);
+	end
+end
+
 _G.array = array