(nodeId: string)
| 234 | |
| 235 | // Assuming that this is a directed acyclic graph, there will be no infinite loop problem. |
| 236 | const walkGraph = (nodeId: string) => { |
| 237 | const depth = depthQueue[nodeId] |
| 238 | graph[nodeId].flatMap((id) => { |
| 239 | depthQueue[id] = Math.max(depthQueue[id] ?? 0, depth + 1) |
| 240 | walkGraph(id) |
| 241 | }) |
| 242 | } |
| 243 | |
| 244 | walkGraph(endNodeId) |
| 245 |