Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

20
LINES

< > BotCompany Repo | #121 // compare tables

Lua code

1  
function compareTables(t1, t2)
2  
  if type(t1) ~= 'table' or type(t2) ~= 'table' then
3  
    return t1 == t2
4  
  end
5  
  
6  
  -- compare common elements, check for extra elements in t1
7  
  for k, v in pairs(t1) do
8  
    local v2 = t2[k]
9  
    if not compareTables(v, v2) then return false end
10  
  end
11  
  
12  
  -- check for extra elements in t2
13  
  for k, v in pairs(t2) do
14  
    local v1 = t1[k]
15  
    if v1 == nil then return false end
16  
  end
17  
  
18  
  -- all matched, tables are equal
19  
  return true
20  
end

test run  test run with input  download  show line numbers   

Relations

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Image recognition results

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: 1367 / 536
Referenced in: [show references]