Skip to content

Instantly share code, notes, and snippets.

@Dobby233Liu
Last active April 20, 2020 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dobby233Liu/8ea63af56400892f2d98fc9e21ed7aed to your computer and use it in GitHub Desktop.
Save Dobby233Liu/8ea63af56400892f2d98fc9e21ed7aed to your computer and use it in GitHub Desktop.
ineffective way to dedup a table in lua
-- deduplicate value-only table
function dedupTable(origtable)
function tableContainsV(tablee, value)
local fr = false
for i = 1, #tablee do
if tablee[i] == value then
fr = true
break -- i had breakfast today
end
end
return fr
end
local messtable = {}
local ie = 0
for i = 1, #origtable do
if not tableContainsV(messtable, origtable[i]) then
ie = ie + 1
messtable[ie] = origtable[i]
-- else DEBUG("dupe!!! origtable["..i.."]")
end
end
return messtable
end
function _DeDupTool_consoleDemo()
print("{ "..table.concat(dedupTable({1,1,2,8,8,8,8,9}),",").." }")
end
_DeDupTool_consoleDemo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment