Skip to content

Instantly share code, notes, and snippets.

@arikan
Last active December 10, 2015 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save arikan/4396945 to your computer and use it in GitHub Desktop.
Save arikan/4396945 to your computer and use it in GitHub Desktop.
get unlinked nodes for a given node (aka. forEachUnlinkedNode)
forEachUnlinkedNode : function (nodeId, callback) {
var node = this.getNode(nodeId),
i,
link,
linkedNodeId;
if (node && node.links && typeof callback === 'function') {
var linkedNodes = [];
for (i = 0; i < node.links.length; ++i) {
link = node.links[i];
linkedNodeId = link.fromId === nodeId ? link.toId : link.fromId;
linkedNodes.push(nodes[linkedNodeId]);
}
var unlinkedNodes = _.difference(nodes, linkedNodes); // array diff of linkedNodes from all nodes
for (i = 0; i < unlinkedNodes.length; ++i) {
callback(unlinkedNodes[i]);
}
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment