feat: finish file-graph-algorithm (check required)

This commit is contained in:
Chen, Tai-Lin committed 2023-08-28 14:39:52 +08:00
1 parent 1b51346eb9
commit 7041e89a49
2 files changed
+41

No files matched your search

+18
View File
@@ -92,4 +92,22 @@ export default class FileNode extends File {
.join('')
return `${indent}${this.name}${suffix}\n${childrenString}`
}
findNode(fileToFind) {
const pathFolders = fileToFind.path
.split('/')
.filter((folder) => folder.length > 0)
let currentNode = this
for (const folder of pathFolders) {
currentNode = currentNode.children.find(
(child) => child.name === folder && child.type === 'folder'
)
if (!currentNode) {
return null
}
}
return currentNode
}
}