Before you mark this question as duplicate of this please read the whole thing:
I have a table in Lua which is a table of tables something like the below one and I want to remove all the duplicate tables in it.
table1 = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3, 4}}
What I want to do is to remove the duplicate tables and use only one. The result should be like the one below
table2 = {{1, 2, 3}, {1, 2, 3, 4}}
I tried a lot of methods I found online and some of my own and I couldn't get to do it.
Here is what I tried last
local test = {1,2,4,2,3,4,2,3,4,"A", "B", "A"}
local hash = {}
local res = {}
for _,v in ipairs(test) do
if (not hash[v]) then
res[#res+1] = v -- you could print here instead of saving to result table if you wanted
hash[v] = true
end
end
-- Here the test is the input, and res is the output table without
-- any duplicates but this works only for values in it and not for
-- nested tables.
Please help me out.