Open cjgodfather opened 4 years ago
this
should always exist. Since there is no restriction on parameters in JS, if node is undefined/null, setRight(node)
is the same as removing the right child. If this line is omitted, this.right.parent = this;
has a possibility of calling null.parent
which would throw an error, since this.right = node
from the previous line.
https://github.com/trekhleb/javascript-algorithms/blob/ba2d8dc4a8e27659c1420fe52390cb7981df4a94/src/data-structures/tree/BinaryTreeNode.js#L133