function bfs(startingNode, graph = [], visited = {}) {
  const nodes = []

  function bfsHelper(vertex) {
    nodes.push(vertex)

    visited[vertex] = true

    for (const node of graph[vertex]) {
      if (!visited[node]) {
        bfsHelper(node)
      }
    }
  }

  dfsHelper(startingNode)

  return nodes
}

module.exports = bfs
