Created
July 1, 2016 05:34
-
-
Save sungwoncho/8caf7f3d9e56741c0631cda134e01832 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
// Given path and value, get an object | |
// e.g. getObj('a.b.c', 1) | |
// { a: { b: { c: 1 } } } | |
function getObj(path, val) { | |
const keys = path.split('.'); | |
if (keys.length === 1) { | |
const current = keys[0]; | |
return { | |
[current]: val | |
}; | |
} else { | |
const current = keys.shift(); | |
const obj = getSourceObj(keys.join('.'), val); | |
return { | |
[current]: obj | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment