Last active
April 25, 2020 06:05
-
-
Save adslaton/0082e64ee8cf9a31568cdc351801ba23 to your computer and use it in GitHub Desktop.
quick-find-eager-solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const connections = [ | |
{ | |
id: 0, | |
name: 0 | |
}, | |
{ | |
id: 1, | |
name: 1 | |
}, | |
{ | |
id: 1, | |
name: 2 | |
}, | |
{ | |
id: 8, | |
name: 3 | |
}, | |
{ | |
id: 8, | |
name: 4 | |
}, | |
{ | |
id: 0, | |
name: 5 | |
}, | |
{ | |
id: 0, | |
name: 6 | |
}, | |
{ | |
id: 1, | |
name: 7 | |
}, | |
{ | |
id: 8, | |
name: 8 | |
}, | |
{ | |
id: 8, | |
name: 9 | |
} | |
]; | |
const union = (p, q) => { | |
connections.map((element, i) => { | |
if (element.name === p) { | |
const pid = element.id; // Maintain the element.id | |
element.id = q; | |
connections.map((el, idx) => { // | |
if (el.id === pid) { // | |
el.id = q; // Change all entries | |
} // | |
}); // | |
} | |
}) | |
}; | |
const connected = (p, q) => { | |
let connection = false; | |
connections.map((element, i) => { | |
if (element.name === p && element.id === q) { | |
connection = true; | |
} | |
}) | |
return connection; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment