Hide all Nodes that don't link any other nodes

Hi Team,

I want to hide automatically all the node(orphan nodes) that are not linked to the other nodes or linked to the tree. How can i achieve this?

Thanks

    myDiagram.nodes.each(function(n) {
        n.visible = (n.linksConnected.count !== 0);
    });