Created
April 1, 2012 06:02
-
-
Save davidchambers/2271874 to your computer and use it in GitHub Desktop.
Dictionary comprehensions in CoffeeScript
This file contains 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
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