Merge pull request #481 from Xertis/patch-8

table.filter bug fix
This commit is contained in:
MihailRis 2025-03-07 01:37:21 +03:00 committed by GitHub
commit 345e140aab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -151,9 +151,27 @@ function table.map(t, func)
end
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
if not func(i, v) then
t[i] = nil
local i_type = type(i)
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