Last active
April 25, 2020 04:37
-
-
Save adslaton/0903a251608d93453b1c029d73dab47c to your computer and use it in GitHub Desktop.
dynamic-connectivity
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: 1, | |
name: 1 | |
}, | |
{ | |
id: 2, | |
name: 2 | |
}, | |
{ | |
id: 3, | |
name: 3 | |
} | |
]; | |
const union = (p, q) => { | |
connections.map((element, i) => { | |
if (element.id === p) { | |
element.id = q; | |
} | |
}) | |
}; | |
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