Last active
October 20, 2021 13:18
-
-
Save uga-rosa/9be272f29522deaa826780f4ff806040 to your computer and use it in GitHub Desktop.
Chacks if t is an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function tbl_copy(t) | |
if type(t) ~= "table" then | |
return t | |
end | |
local res = {} | |
for k, v in pairs(t) do | |
res[k] = tbl_copy(v) | |
end | |
return setmetatable(res, getmetatable(t)) | |
end | |
local function is_array(t) | |
local _t = tbl_copy(t) | |
for i = 1, #t do | |
if _t[i] == nil then | |
return false | |
end | |
_t[i] = nil | |
end | |
if next(_t) then | |
return false | |
end | |
return true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment