Function
findNodeInTreeById
(
nodes: T[],
id: string
)
Source from the content-addressed store, hash-verified
| 722 | |
| 723 | // Finds the node in the list of nodes or recursively in the children |
| 724 | function findNodeInTreeById<T extends { id: string; children?: T[] }>( |
| 725 | nodes: T[], |
| 726 | id: string |
| 727 | ): T | undefined { |
| 728 | const node = nodes.find((node) => node.id === id); |
| 729 | |
| 730 | if (node) { |
| 731 | return node; |
| 732 | } |
| 733 | |
| 734 | for (const node of nodes) { |
| 735 | const foundNode = findNodeInTreeById(node.children || [], id); |
| 736 | |
| 737 | if (foundNode) { |
| 738 | return foundNode; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | return; |
| 743 | } |
| 744 | |
| 745 | function calculatePathToNode<T extends { id: string; children?: T[] }>( |
| 746 | nodes: T[], |
Tested by
no test coverage detected