table扩展模块新增一个方法
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
local rnd=math.random
|
||||||
local find=string.find
|
local find=string.find
|
||||||
local rem=table.remove
|
local rem=table.remove
|
||||||
local next,type=next,type
|
local next,type=next,type
|
||||||
@@ -58,7 +59,6 @@ function TABLE.coverR(new,old)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--For all things in new if same type in old, push to old
|
--For all things in new if same type in old, push to old
|
||||||
function TABLE.update(new,old)
|
function TABLE.update(new,old)
|
||||||
for k,v in next,new do
|
for k,v in next,new do
|
||||||
@@ -84,6 +84,19 @@ function TABLE.complete(new,old)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
--Pop & return random [1~#] of table
|
||||||
|
function TABLE.popRandom(t)
|
||||||
|
local l=#t
|
||||||
|
if l>0 then
|
||||||
|
local r=rnd(l)
|
||||||
|
r,t[r]=t[r],t[l]
|
||||||
|
t[l]=nil
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--Remove [1~#] of table
|
--Remove [1~#] of table
|
||||||
function TABLE.cut(G)
|
function TABLE.cut(G)
|
||||||
for i=1,#G do
|
for i=1,#G do
|
||||||
@@ -98,6 +111,8 @@ function TABLE.clear(G)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--------------------------
|
||||||
|
|
||||||
--Remove duplicated value of [1~#]
|
--Remove duplicated value of [1~#]
|
||||||
function TABLE.trimDuplicate(org)
|
function TABLE.trimDuplicate(org)
|
||||||
local cache={}
|
local cache={}
|
||||||
@@ -122,6 +137,7 @@ function TABLE.remDuplicate(org)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--------------------------
|
||||||
|
|
||||||
--Reverse [1~#]
|
--Reverse [1~#]
|
||||||
function TABLE.reverse(org)
|
function TABLE.reverse(org)
|
||||||
|
|||||||
Reference in New Issue
Block a user