Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a tree with path string created by MattMcFarland - https://repl.it/JC8r/22
const pathString = 'one/two/three';
function buildTree(pathString) {
const pathArray = pathString.split('/')
let pathList = {}
for (var i = pathArray.length - 1; i >= 0; i--) {
let newObj = Object.assign({}, pathList);
pathList = {
[pathArray[i]]: newObj
}
}
console.log(pathList)
}
buildTree(pathString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment