Skip to content

Instantly share code, notes, and snippets.

@MattMcFarland
Created June 30, 2017 20:55
Show Gist options
  • Save MattMcFarland/3d7bf94220ae172669d605a3300ce177 to your computer and use it in GitHub Desktop.
Save MattMcFarland/3d7bf94220ae172669d605a3300ce177 to your computer and use it in GitHub Desktop.
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