setLeft(node) {
// Reset parent for left node since it is going to be detached.
if (this.left) {
this.left.parent = null;
}
// Attach new node to the left.
this.left = node;
// Make current node to be a parent for new left one.
if (this.left) {
this.left.parent = this;
}
return this;
}
I think this
if (this.left) {
this.left.parent = null;
}
portion of the code is redundant. Since we are assigning this.left = node, the previous node is going to be garbage collected and we don't need to explicitly assign this.left.parent = null.
Correct me If I'm wrong.
I think this
portion of the code is redundant. Since we are assigning this.left = node, the previous node is going to be garbage collected and we don't need to explicitly assign this.left.parent = null. Correct me If I'm wrong.