Skip to content

Instantly share code, notes, and snippets.

@nightkr
Created November 9, 2012 21:38
Show Gist options
  • Save nightkr/245cf74e23f711d4d3fa to your computer and use it in GitHub Desktop.
Save nightkr/245cf74e23f711d4d3fa to your computer and use it in GitHub Desktop.
Map
function map(f, seq)
local output = {}
for i=1,#seq do
output[i] = f(seq[i])
end
return output
end
local wassup = map(string.char, {119, 97, 115, 115, 117, 112})
local expected = {"w", "a", "s", "s", "u", "p"}
assert(#wassup == #expected)
for i=1,#wassup do
assert(wassup[i] == expected[i])
end
assert(#map(string.char, {}) == 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment