Given edges, I would like exclude any edge which have both nodes points.
nodes = ['1', '2', '3', '4']
edges = [
{id: 'a', src: '1', target: '2'}, <<exclude cuz '1', '2' are in nodes
{id: 'b', src: '4', target: '3'}, <<exclude
{id: 'c', src: '1', target: '5'}, <<DO NOT exclude cuz only '1' is in nodes
{id: 'd', src: '6', target: '2'}, <<DO NOT
{id: 'e', src: '6', target: '8'}, <<DO NOT
]
output = ['c', 'd', 'e']
Can you complete the below statement..?? Or do you have any efficient solution?
nodes = ['1', '2', '3', '4']
edges = [
{id: 'a', src: '1', target: '2'}, //exclude cuz '1', '2' are in nodes
{id: 'b', src: '4', target: '3'}, //exclude
{id: 'c', src: '1', target: '5'}, //DO NOT exclude cuz only '1' is in nodes
{id: 'd', src: '6', target: '2'}, //DO NOT
{id: 'e', src: '6', target: '8'}, //DO NOT
]
console.log(edges.filter({src, target} => nodes.includes(src) && nodes.includes(target)).map({id}=>id));
nodes.includes(src) && nodes.includes(target)in parentheses and use the!operator, since this describes exactly the condition you want to exclude.()around it.