-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.lua
More file actions
30 lines (26 loc) · 709 Bytes
/
Copy pathtools.lua
File metadata and controls
30 lines (26 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
local floor, random = math.floor, math.random
---@param t table
---@param fnKeep function
---@return table
function ArrayRemove(t, fnKeep)
local j, n = 1, #t;
for i=1,n do
if (fnKeep(t, i, j)) then
-- Move i's kept value to j's position, if it's not already there.
if (i ~= j) then
t[j] = t[i];
t[i] = nil;
end
j = j + 1; -- Increment position of where we'll place the next kept value.
else
t[i] = nil;
end
end
return t;
end
--- Don't forget to call math.randomseed at initialization
---@param n number
---@return integer
function Rand(n)
return floor(random() * n)
end