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

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

    visited[vertex] = true

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

  dfsHelper(startingNode)

  return nodes
}

module.exports = dfsRecursive
