Created
June 30, 2017 20:55
-
-
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
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
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