Skip to content

Instantly share code, notes, and snippets.

@knjname
Created August 10, 2012 17:06
Show Gist options
  • Save knjname/3315705 to your computer and use it in GitHub Desktop.
Save knjname/3315705 to your computer and use it in GitHub Desktop.
# requires underscore.js
foldl = (ls, fn, head) ->
head = fn head, e for e in ls
head
console.log foldl [1..10], ((l,r)->l+r), 0
accessPropByNames = (obj, names) ->
foldl names, ((l,r)-> l?[r]), obj
o = {a : { b : { c : 3}}}
console.log accessPropByNames o, "a.b.c".split('.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment