Skip to content

Instantly share code, notes, and snippets.

@fackux
Last active November 27, 2021 21:58
Show Gist options
  • Save fackux/d86c90031b285543d1c6475f95aca254 to your computer and use it in GitHub Desktop.
Save fackux/d86c90031b285543d1c6475f95aca254 to your computer and use it in GitHub Desktop.
graphData.haveItem.js
const graphData = {
nodes: [
{id:1, name:'Facu'},
{id:2, name:'Cari'},
{id:3, name:'Fran'},
{id:4, name:'Martina'}
],
links: [
{source:1, target:2},
{source:3, target:2},
{source:3, target:1},
{source:4, target:1},
]
}
const haveLinks = (node, links) => Boolean(links.filter(link=>link.source===node.id).length || links.filter(link=>link.target===node.id).length)
const unlinkedNodes = ({nodes, links}) => !nodes.every(node => haveLinks(node, links))
console.log(unlinkedNodes(graphData)) // -> false
graphData.links.pop()
console.log(unlinkedNodes(graphData)) // -> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment