From 1c9cb673257684b34addfe08088bd0df7988df47 Mon Sep 17 00:00:00 2001 From: Stephen Leitnick Date: Sat, 22 Dec 2018 18:00:12 -0500 Subject: [PATCH] Fixed Filter function for arrays --- .../Aero/Shared/TableUtil.modulescript.lua | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ReplicatedStorage/Aero/Shared/TableUtil.modulescript.lua b/src/ReplicatedStorage/Aero/Shared/TableUtil.modulescript.lua index 0f65f1f..71bbe98 100644 --- a/src/ReplicatedStorage/Aero/Shared/TableUtil.modulescript.lua +++ b/src/ReplicatedStorage/Aero/Shared/TableUtil.modulescript.lua @@ -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