countComponents = function (n, edges, count = 0) {
    const { graph, visited } = buildGraph(n, edges);

    for (const node in graph) {
        if (hasPath(graph, node, visited)) count++;
    }

    return count;
}
https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/
Time O(V + E) | Space O(V + E)
@param {number} n
@param {number[][]} edges
@return {number}