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

Commit

Permalink
Use table.find for IndexOf
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleitnick committed Jan 6, 2020
1 parent 3465830 commit ba6b359
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/ReplicatedStorage/Aero/Shared/TableUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@
Returns the index of the given item in the table. If not found, this
will return nil.
This is the same as table.find, which Roblox added after this method
was written. To keep backwards compatibility, this method will continue
to exist, but will point directly to table.find.
local tbl = {"Hello", 32, true, "abc"}
local abcIndex = TableUtil.IndexOf("abc") -- > 4
local helloIndex = TableUtil.IndexOf("Hello") -- > 1
Expand Down Expand Up @@ -206,6 +210,8 @@ local TableUtil = {}

local http = game:GetService("HttpService")

local IndexOf = table.find


local function CopyTable(t)
assert(type(t) == "table", "First argument must be a table")
Expand Down Expand Up @@ -400,16 +406,6 @@ local function Print(tbl, label, deepPrint)
end


local function IndexOf(tbl, item)
for i = 1,#tbl do
if (tbl[i] == item) then
return i
end
end
return nil
end


local function Reverse(tbl)
local n = #tbl
local tblRev = table.create(n)
Expand Down

0 comments on commit ba6b359

Please sign in to comment.