const buildTreeOutline = (topLevelNodes) => {
const buildTree = (topLevelNode, currentLevel) => {
const parentContainer = document.createElement("div");
parentContainer.style.marginLeft = "30px";
const parentName = document.createElement("span");
parentName.innerText = `* ${topLevelNode.name}`;
parentContainer.appendChild(parentName);
const newChildren = topLevelNode.children.map((child) =>
buildTree(child, currentLevel + 1)
if (newChildren.length > 0) {
newChildren.forEach((newChild) => parentContainer.appendChild(newChild));
topLevelNodes.forEach((topLevelNode) =>
document.querySelector("body").appendChild(buildTree(topLevelNode, 0))
constructor(name, children = []) {
this.children = children;
const topLevelNode1 = new TreeNode("folder1/");
topLevelNode1.children.push(new TreeNode("file1.js"));
topLevelNode1.children.push(new TreeNode("file2.js"));
topLevelNode1.children.push(new TreeNode("subfolder1/", [new TreeNode("subfile.png")]));
const topLevelNode2 = new TreeNode("folder2/");
topLevelNode2.children.push(new TreeNode("file3.js"));
topLevelNode2.children.push(new TreeNode("file4.js"));
const topLevelNodes = [topLevelNode1, topLevelNode2];
buildTreeOutline(topLevelNodes);