JavaScript Clean Union Find
javascript\nvar findRedundantConnection = function(edges) {\n    \n    class UnionFind {\n        constructor(n) {\n            this.graph = [...Array(n)].map((
```javascript\nvar findRedundantConnection = function(edges) {\n    \n    class UnionFind {\n        constructor(n) {\n            this.graph = [...Array(n)].map((_, i) => i);\n            this.extra = null;\n        }\n        \n        find(id) {\n            if(this.graph[id] === id) return id;\n            this.graph[id] = this.find(this.graph[id]);\n            return this.graph[id];\n        }\n        \n        union(x, y) {\n            const rootX = this.find(x);\n            const rootY = this.find(y);\n            if(rootX !== rootY) this.graph[rootY] = rootX;\n            else this.extra = [x, y]\n        }\n    }\n    \n    const unionfind = new UnionFind(edges.length+1);\n    \n    for(let [u, v] of edges) {\n        unionfind.union(u, v);\n    }\n    return unionfind.extra;   \n};\n```
['Union Find', 'JavaScript']