Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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