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

25
LINES

< > BotCompany Repo | #349 // Table functions (valuestokeys, keystolist, all)

Lua code

function valuestokeys(tbl)
  local tbl2 = {}
  for _, v in pairs(tbl) do
    tbl2[v] = true
  end
  return tbl2
end

function keystolist(tbl)
  local tbl2 = {}
  for k, _ in pairs(tbl) do
    table.insert(tbl2, k)
  end
  return tbl2
end

-- iterate over values of an array
function all(t)
  local i = 0
  local n = #t
  return function ()
    i = i + 1
    if i <= n then return t[i] end
  end
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

Snippet ID: #349
Snippet name: Table functions (valuestokeys, keystolist, all)
Eternal ID of this version: #349/1
Text MD5: 3504c79f98d8c271dcd27bf7d4acc341
Author: stefan
Category:
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-03-13 16:57:37
Source code size: 422 bytes / 25 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 820 / 228
Referenced in: #344 - Liberation Sans Recognizer with fixes
#351 - Liberation Sans Recognizer with space detection
#352 - Liberation Sans Recognizer (compressed code)
#353 - Phone number recognizer (digits plus slash)
#366 - Magic Wand All
#368 - Magic Wand All size=4
#384 - Magic Wand All, optimized
#385 - Magic Wand All size=3
#386 - Magic Wand + Hashes
#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)
#466 - Color buckets
#476 - Haiku font recognizer (collecting data)
#524 - Find snippet references in a text
#526 - Print reference tree for #2000027
#528 - Return reference tree (generic)
#529 - Extraction task solver (on example task: #2000060)
#530 - Find "Need bridge" snippets & present questionnaire
#532 - Make bridge map (getBridgeMap)
#536 - Return reference tree (without bridge stuff & invalidated)
#537 - printShortenedReferenceTree
#633 - Find single translator chain
#1000234 - Print reference tree for #2000044
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)