Last active
December 10, 2015 06:48
-
-
Save arikan/4396945 to your computer and use it in GitHub Desktop.
get unlinked nodes for a given node (aka. forEachUnlinkedNode)
This file contains hidden or 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
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