remove = Tree.prototype.remove = function remove( value ) {
var node = this.find( value ).current;
var parent = this.find( value ).parent;
var topMostLeft = null;
if ( !node ) return null;
if ( !node.left ) {
if ( !node.right ) {
this.updateTreeParentNode( parent, node, null );
} else {
this.updateTreeParentNode( parent, node, node.right );
}
} else if ( !node.right.left ) {
node.right.left = node.left;
this.updateTreeParentNode( parent, node, node.right );
} else {
topMostLeft = this.findTopMostLeft( node.right );
topMostLeft.parent.left = null;
topMostLeft.node.left = node.left;
topMostLeft.node.right = node.right;
this.updateTreeParentNode( parent, node, topMostLeft.node );
}
this.count -= 1;
}