Skip to content

Instantly share code, notes, and snippets.

@davidchambers
Created April 1, 2012 06:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidchambers/2271874 to your computer and use it in GitHub Desktop.
Save davidchambers/2271874 to your computer and use it in GitHub Desktop.
Dictionary comprehensions in CoffeeScript
to_hash = (pairs) ->
hash = {}
hash[key] = value for [key, value] in pairs
hash
# usage:
to_hash ([n, n * n] for n in [0..5]) # {0:0, 1:1, 2:4, 3:9, 4:16, 5:25}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment