• Comparing 2 tables.
    1 replies, posted
I need to compare 2 tables and have it return the values that aren't the same. Ex: table1 = {a, b , c} table2 = {a, b, c, d} It will return d or at least find it.
[lua] function compareTables(t1, t2) local v = {} for _, i in pairs(t1) do if not table.HasValue(t2, i) then table.insert(v, i) end end for _, i in pairs(t2) do if not table.HasValue(t1, i) then table.insert(v, i) end end return v end [/lua] Something I wrote in 2 minutes, should work. [lua] table1 = {a, b, c} table2 = {a, b, c, d} local missingValues = compareTables(table1, table2) [/lua]
Sorry, you need to Log In to post a reply to this thread.