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