| 3 | // BREADTH-FIRST SEARCH |
| 4 | |
| 5 | class Node { |
| 6 | constructor(name) { |
| 7 | this.name = name; |
| 8 | this.children = []; |
| 9 | } |
| 10 | |
| 11 | addChild(name) { |
| 12 | this.children.push(new Node(name)); |
| 13 | return this; |
| 14 | } |
| 15 | |
| 16 | breadthFirstSearch(array) { |
| 17 | const queue = [this]; |
| 18 | while (queue.length > 0) { |
| 19 | const curretNode = queue.shift(); |
| 20 | array.push(curretNode.name); |
| 21 | for (let child of curretNode.children) { |
| 22 | queue.push(child); |
| 23 | } |
| 24 | } |
| 25 | return array; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | const graph = new Node("A"); |
| 30 | graph.addChild("B").addChild("C").addChild("D"); |
nothing calls this directly
no outgoing calls
no test coverage detected