SOURCE

const pathList = [
    '/e/f',
    '/a/b/c/d',
    '/e'
]

function pathFormat(pathList) {
    const answer = {}
    pathList.forEach(path => {
        let next = answer
        const arr = path.split('/')
        arr.filter(item => item !== '').forEach(item => {
            if (!next[item]) {
                next[item] = {}
            }
            next = next[item]
        })
    })
    return answer
}

// function pathFormat(pathList) {
//   return pathList.reduce((answer, path) => {
//     path
//       .split('/')
//       .filter((dir) => dir)
//       .reduce((temp, dir) => {
//         if (!temp[dir]) temp[dir] = {};
//         return temp[dir];
//       }, answer);
//     return answer;
//   }, {});
// }

console.log(pathFormat(pathList))
console 命令行工具 X clear

                    
>
console