Skip to content

Instantly share code, notes, and snippets.

@adslaton
Last active April 25, 2020 04:37
Show Gist options
  • Save adslaton/0903a251608d93453b1c029d73dab47c to your computer and use it in GitHub Desktop.
Save adslaton/0903a251608d93453b1c029d73dab47c to your computer and use it in GitHub Desktop.
dynamic-connectivity
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