mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 14:31:50 +00:00
commit
345e140aab
1 changed files with 20 additions and 2 deletions
|
|
@ -151,9 +151,27 @@ function table.map(t, func)
|
||||||
end
|
end
|
||||||
|
|
||||||
function table.filter(t, func)
|
function table.filter(t, func)
|
||||||
|
|
||||||
|
for i = #t, 1, -1 do
|
||||||
|
if not func(i, t[i]) then
|
||||||
|
table.remove(t, i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local size = #t
|
||||||
|
|
||||||
for i, v in pairs(t) do
|
for i, v in pairs(t) do
|
||||||
if not func(i, v) then
|
local i_type = type(i)
|
||||||
t[i] = nil
|
if i_type == "number" then
|
||||||
|
if i < 1 or i > size then
|
||||||
|
if not func(i, v) then
|
||||||
|
t[i] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if not func(i, v) then
|
||||||
|
t[i] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue