Last active
November 14, 2021 22:33
-
-
Save ryanpcmcquen/7aca8ba7f9bce67d3a375fee72094cf3 to your computer and use it in GitHub Desktop.
Kind of like `Object.assign()` for Lua.
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 combineTables(...) | |
local combinedTable = {} | |
local arg = {...} | |
for k, v in pairs(arg) do | |
if type(v) == 'table' then | |
for tk, tv in pairs(v) do | |
table.insert(combinedTable, tv) | |
end | |
end | |
end | |
return combinedTable | |
end |
but, I would say mine is more close to object.assign, I might be understanding you incorrectly by what you mean.
const one = ['ctrl', 'alt'];
const two = ['shift'];
console.log(Object.assign(one, two));
// [ 'shift', 'alt' ]
Object.assign
isn't meant to apply to arrays. What are you trying to accomplish with your snippet?
Yeah I agree with that, but my code would do the same as Object.assign would do, which is what the gist is trying to do (I think, but this is what came up when searching for that).
This gist is more like concat
It wouldn't do the same things for objects though. The intention of the gist is to combine tables.
This does for tables what Object.assign
does for objects.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ha6000, I should have clarified, I am thinking of JavaScript's
Object.assign()
:https://repl.it/@ryanpcmcquen/CoarseCorruptDiskdrive