function compareTables(t1, t2) if type(t1) ~= 'table' or type(t2) ~= 'table' then return t1 == t2 end -- compare common elements, check for extra elements in t1 for k, v in pairs(t1) do local v2 = t2[k] if not compareTables(v, v2) then return false end end -- check for extra elements in t2 for k, v in pairs(t2) do local v1 = t1[k] if v1 == nil then return false end end -- all matched, tables are equal return true end
test run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Recognizer | Recognition Result | Visualize | Recalc |
---|---|---|---|
#308 | 488 | [visualize] |
Snippet ID: | #121 |
Snippet name: | compare tables |
Eternal ID of this version: | #121/1 |
Text MD5: | 172fa9c26cec6151d2f448195eda10ee |
Author: | stefan |
Category: | general lua functions |
Type: | Lua code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2014-01-10 19:38:08 |
Source code size: | 488 bytes / 20 lines |
Pitched / IR pitched: | Yes / Yes |
Views / Downloads: | 1365 / 535 |
Referenced in: | [show references] |