1var findRedundantConnection = function (edges) {2const root = [];3const find = (index) => {4const next = root[index];5return next ? find(next) : index;6};78for (const [a, b] of edges) {9const x = find(a);10const y = find(b);1112if (x === y) return [a, b];13root[x] = y;14}15};