function removeSubsets(nodes) {
    let idx = nodes.length;
    /*
     * Check if each node (or one of its ancestors) is already contained in the
     * array.
     */
    while (--idx >= 0) {
        const node = nodes[idx];
        /*
         * Remove the node if it is not unique.
         * We are going through the array from the end, so we only
         * have to check nodes that preceed the node under consideration in the array.
         */
        if (idx > 0 && nodes.lastIndexOf(node, idx - 1) >= 0) {
            nodes.splice(idx, 1);
            continue;
        }
        for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
            if (nodes.includes(ancestor)) {
                nodes.splice(idx, 1);
                break;
            }
        }
    }
    return nodes;
}
/**
 * Given an array of nodes, remove any member that is contained by another.
 *
 * @category Helpers
 * @param nodes Nodes to filter.
 * @returns Remaining nodes that aren't subtrees of each other.
 */
Given an array of nodes, remove any member that is contained by another.
@category Helpers
@param nodes Nodes to filter.
@returns Remaining nodes that aren't subtrees of each other.
Given an array of nodes remove any member that is contained by another . @category Helpers @param nodes Nodes to filter . @returns Remaining nodes that aren ' t subtrees of each other .
function removeSubsets(nodes) {
    let idx = nodes.length;
    while (--idx >= 0) {
        const node = nodes[idx];
        if (idx > 0 && nodes.lastIndexOf(node, idx - 1) >= 0) {
            nodes.splice(idx, 1);
            continue;
        }
        for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
            if (nodes.includes(ancestor)) {
                nodes.splice(idx, 1);
                break;
            }
        }
    }
    return nodes;
}
function removeSubsets ( nodes ) { let idx = nodes . length ; while ( -- idx >= 0 ) { const node = nodes [ idx ] ; if ( idx > 0 && nodes . lastIndexOf ( node , idx - 1 ) >= 0 ) { nodes . splice ( idx , 1 ) ; continue ; } for ( let ancestor = node . parent ; ancestor ; ancestor = ancestor . parent ) { if ( nodes . includes ( ancestor ) ) { nodes . splice ( idx , 1 ) ; break ; } } } return nodes ; }
Given an array of nodes, remove any member that is contained by another.
Given an array of nodes remove any member that is contained by another .
/*
     * Check if each node (or one of its ancestors) is already contained in the
     * array.
     */ /*
         * Remove the node if it is not unique.
         * We are going through the array from the end, so we only
         * have to check nodes that preceed the node under consideration in the array.
         */