How to transform array of strings into specific tree structure in Javascript
问题 I get a list of file paths from the backend, it represents a folder structure and looks like this: paths = ["path/to/file1.doc", "path/to/file2.doc", "foo/bar.doc] The lengths of the paths are arbitrary. In order to use a file tree component (angular2-tree-component) I need to transform this data into the following format: nodes = [ { "name": "path", "children": [ { "name": "to", "children": [ {"name": "file1.doc"}, {"name": "file2.doc"} ] } ] }, { "name": "foo", "children": [ {"name": "bar