Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Fixed Filter function for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleitnick committed Dec 22, 2018
1 parent 9a92eaa commit 1c9cb67
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/ReplicatedStorage/Aero/Shared/TableUtil.modulescript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,19 @@ local function Filter(t, f)
assert(type(t) == "table", "First argument must be a table")
assert(type(f) == "function", "Second argument must be an array")
local newT = {}
for k,v in pairs(t) do
if (f(v, k, t)) then
newT[k] = v
if (#t > 0) then
local n = 0
for k,v in pairs(t) do
if (f(v, k, t)) then
n = (n + 1)
newT[n] = v
end
end
else
for k,v in pairs(t) do
if (f(v, k, t)) then
newT[k] = v
end
end
end
return newT
Expand Down

0 comments on commit 1c9cb67

Please sign in to comment.