feat: add tests for binary search trees by ridge-kimani · Pull Request #1769 · TheAlgorithms/JavaScript
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a shorthand recommendation.
Checking for if(found) { will check for not null and not undefined .
So no need to explicitly use if (found !== null) {
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The search return value can only be null or a Node, hence the implicit check.
search(val) { if (this.value === val) { return this } else if (val < this.value && this.left !== null) { return this.left.search(val) } else if (val > this.value && this.right !== null) { return this.right.search(val) } return null }