Create Tree Challenge

Create a tree from a list of paths

JavaScript

function pathToTree(el, i, items) {
    var parts, leaf;
        
    parts = el.split('/');
    leaf  = this;
    
    _.each(parts, function(el, i, items){
        leaf[el] = leaf[el] || {};
        leaf = leaf[el];
    });
}

function createTree(list) {
    var output;
    
    output = {};
    _.each(list, pathToTree, output);
    
    return output;
}

var list =  ['path/to/file', 'foo/bar/baz', 'foo/zap/zip', 'joe'];

console.log(createTree(list));