MCPcopy Create free account
hub / github.com/marijnh/Eloquent-JavaScript / findPath

Function findPath

code/solutions/22_2_timing.js:1–12  ·  view source on GitHub ↗
(a, b)

Source from the content-addressed store, hash-verified

1function 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
14function time(findPath) {
15 let graph = treeGraph(6, 6);

Callers 2

timeFunction · 0.70
timeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected