(a, b)
| 1 | function findPath(a, b) { |
| 2 | let work = [[a]]; |
| 3 | for (let path of work) { |
| 4 | let end = path[path.length - 1]; |
| 5 | if (end == b) return path; |
| 6 | for (let next of end.edges) { |
| 7 | if (!work.some(path => path[path.length - 1] == next)) { |
| 8 | work.push(path.concat([next])); |
| 9 | } |
| 10 | } |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | let graph = treeGraph(4, 4); |
| 15 | let root = graph[0], leaf = graph[graph.length - 1]; |