Created
May 22, 2011 23:55
-
-
Save pikajude/986019 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| table["map"] = function (tbl, func) | |
| local newtbl = {} | |
| for k, v in pairs(tbl) do | |
| local key, value = (func)(k, v) | |
| if not value then | |
| value = key | |
| key = #newtbl + 1 | |
| end | |
| newtbl[key] = value | |
| end | |
| return newtbl | |
| end | |
| for k, v in pairs(table.map({b = "a", c = "b", a = "c"}, function (k, v) return v, tostring(k) end)) do | |
| print(k, v) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment