Created
April 18, 2013 13:43
-
-
Save rin/5412779 to your computer and use it in GitHub Desktop.
nested hash from array
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
nestedHashFrom = (items) -> | |
hash = {} | |
switch items.length | |
when 1 then hash = items[0] | |
when 2 then hash[items[0]] = items[1] | |
else hash[items[0]] = nestedHashFrom(items[1..-1]) | |
hash | |
nestedHashFrom([model, attr, !currStatus]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment