Revisiting nodes repeats them, so a guard caps the walk here.
Acceptance criteria
- 1.#out should show visited 3.
Revisiting nodes repeats them, so a guard caps the walk here.
const graph = new Map([["a", ["b", "c"]], ["b", ["a"]], ["c", []]]); const order = []; const queue = ["a"]; let head = 0; while (head < queue.length && order.length < 4) { const node = queue[head++]; order.push(node); for (const next of graph.get(node) || []) queue.push(next); } document.querySelector('#out').textContent = "visited " + order.length;
Output ready when you are
Press Run to render your code, or Submit to validate your solution.