We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1ffca52 commit a98602eCopy full SHA for a98602e
binarySearchTree.js
@@ -20,6 +20,17 @@ BST.prototype.insert = function(value) {
20
}
21
};
22
23
+BST.prototype.contains = function(value) {
24
+ if (value === this.value) return true;
25
+ else if (value < this.value) {
26
+ if (!this.left) return false;
27
+ else return this.left.contains(value);
28
+ } else if (value > this.value) {
29
+ if (!this.right) return false;
30
+ else return this.right.contains(value);
31
+ }
32
+};
33
+
34
let bst = new BST(50);
35
36
bst.insert(30);
@@ -34,4 +45,4 @@ bst.insert(85);
45
bst.insert(105);
46
bst.insert(10);
47
37
-console.log(bst.right.right);
48
+console.log(bst.contains(30));
0 commit comments