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

20
LINES

< > BotCompany Repo | #121 // compare tables

Lua code

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   

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: 1366 / 536
Referenced in: #123 - Pitcher core
#138 - String split function (test)
#159 - test for serpent.lua
#363 - Magic Wand Algorithm
#369 - Magic Wand Algorithm (optimized & including magicWandAll)
#398 - Magic Wand Algorithm (optimizing)
#399 - Magic Wand All, optimizing
#400 - Magic Wand All, optimizing II (profiling)
#401 - Magic Wand All, optimizing III (faster x movement)
#402 - Magic Wand + Hashes (optimized III)
#403 - Magic Wand + Hashes (one column)
#404 - Magic Wand + Hashes (column range, improving)
#405 - Magic Wand + Hashes for Internet menu
#406 - Magic Wand + Hashes (special case recognizer)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)