Ad
Code
Diff
  • function set(obj, path, value) {
      if(path.length === 1) {
        return {...obj, [path[0]]: value};
      } 
      
      const first = path.shift();
        
      return {...obj, [first]: set(obj[first] || {}, path, value)};
    }
    
    function getTree(strings) {
      return strings.reduce(function r(tree, curr) {
        return set(tree, curr.split('/'), "file");
      }, {});
    }
    • function set(obj, path, value) {
    • if(path.length === 1) {
    • return {...obj, [path[0]]: value};
    • }
    • const first = path.shift();
    • return {...obj, [first]: set(obj[first] || {}, path, value)};
    • }
    • function getTree(strings) {
    • // code
    • return strings.reduce(function r(tree, curr) {
    • return set(tree, curr.split('/'), "file");
    • }, {});
    • }