(value: T, node: TreeNode<T>)
| 75 | |
| 76 | // Return the path to the node with the given value using DFS |
| 77 | function findPath<T>(value: T, node: TreeNode<T>): TreeNode<T>[] { |
| 78 | if (value === node.value) return [node]; |
| 79 | |
| 80 | for (const child of node.children) { |
| 81 | const path = findPath(value, child); |
| 82 | if (path.length) { |
| 83 | path.unshift(node); |
| 84 | return path; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return []; |
| 89 | } |
| 90 | |
| 91 | export class TreeNode<T> { |
| 92 | constructor( |
no outgoing calls
no test coverage detected
searching dependent graphs…