Last active
November 27, 2021 21:58
-
-
Save fackux/d86c90031b285543d1c6475f95aca254 to your computer and use it in GitHub Desktop.
graphData.haveItem.js
This file contains 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 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