Skip to content

Instantly share code, notes, and snippets.

@veered
Last active January 10, 2017 21:18
Show Gist options
  • Save veered/b6ba8c4d202725e9b1a6 to your computer and use it in GitHub Desktop.
Save veered/b6ba8c4d202725e9b1a6 to your computer and use it in GitHub Desktop.
Get Value Challenge
function get(doc, path) {
}
doc = {
'a': {
'b': {
'c': 'hello'
},
'd': {
'c': 'sup',
'e': {
'f': 'blah blah blah'
}
}
}
}
get(doc, 'a.d.e.f')
// {'a.d.e.f': 'blah blah blah'}
get(doc, 'a.*.c')
// {'a.b.c': 'hello', 'a.d.c': 'sup'}
get(doc, 'a.*.e')
// {'a.d.e': {'f': 'blah blah blah'}}}
get(doc, 'a.b.c.e.*')
// {}
get(doc, '*')
// {'a':{'b':{'c':'hello'},'d':{'c':'sup','e':{'f':'blah blah blah'}}}}
get(doc, '')
// {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment