Created
July 17, 2013 18:49
-
-
Save nasser/6023321 to your computer and use it in GitHub Desktop.
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
// Parse string +path+ into nested objects within +object+ and assign | |
// the deepest key to +value+, without overwriting existing keys. | |
// Examples follow. | |
function parse(path, value, object) { } | |
parse("foo", 42, {}); // => { foo: 42 } | |
parse("foo.bar", 42, {}); // => { foo: { bar: 42 } } | |
parse("foo.bar.baz", 42, {}); // => { foo: { bar: { baz: 42 } } } | |
parse("foo", 42, { challenge: "accepted" }); // => { foo: 42, challenge: 'accepted' } | |
parse("foo.bar", 42, { challenge: "accepted" }); // => { foo: { bar: 42 }, challenge: 'accepted' } | |
parse("foo", 42, { foo: "accepted" }); // => { foo: 'accepted' } | |
parse("foo.bar", 42, { foo: { baz: "qux" } }); // => { foo: { baz: 'qux', bar: 42 } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment