Spot the bug in the reachability helper

from Trees and graphs
Node 24 beginner 4 min 1 issue to find

Find the bug in this generated reachability helper.

JavaScript
function collectReachable(graph, start) {
  const order = [];

  function visit(vertex) {
    order.push(vertex);
    for (const neighbor of graph.get(vertex) ?? []) {
      visit(neighbor);
    }
  }

  visit(start);
  return order;
}
Open in playground
Report an error