Skip to content

Instantly share code, notes, and snippets.

@rin
Created April 18, 2013 13:43
Show Gist options
  • Save rin/5412779 to your computer and use it in GitHub Desktop.
Save rin/5412779 to your computer and use it in GitHub Desktop.
nested hash from array
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