Skip to content

Instantly share code, notes, and snippets.

@adslaton
Last active April 25, 2020 05:13
Show Gist options
  • Save adslaton/69722ed82b60fd474a0d24ba9999f6f7 to your computer and use it in GitHub Desktop.
Save adslaton/69722ed82b60fd474a0d24ba9999f6f7 to your computer and use it in GitHub Desktop.
quick-find-eager
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) {
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