Comparison

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
comparison
equal deleted inserted replaced
921:f97d37a7d8a6 922:0e45234360cd
42 local r = math.random(i,len); 42 local r = math.random(i,len);
43 self[i], self[r] = self[r], self[i]; 43 self[i], self[r] = self[r], self[i];
44 end 44 end
45 end 45 end
46 46
47 function array:reverse()
48 local len = #self-1;
49 for i=len,1,-1 do
50 self:push(self[i]);
51 self:pop(i);
52 end
53 end
54
47 _G.array = array 55 _G.array = array