Skip to content

Commit

Permalink
min, max and samallestNode changed
Browse files Browse the repository at this point in the history
  • Loading branch information
DNonov committed Feb 25, 2018
1 parent 76b1ef5 commit 9ae5813
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions src/binarySearchTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ function BST() {
}

this.min = function () {
let currentNode = this.root;
while (!(currentNode.left === null)) {
currentNode = currentNode.left;
}
return currentNode.data;
const result = (function minNode(currentNode) {
if(currentNode.left === null) return currentNode.data;
return minNode(currentNode.left);
})(this.root);
return result;
}

this.max = function () {
let currentNode = this.root;
while (!(currentNode.right === null)) {
currentNode = currentNode.right;
}
return currentNode.data;
const result = (function minNode(currentNode) {
if(currentNode.right === null) return currentNode.data;
return minNode(currentNode.right);
})(this.root);
return result;
}

this.find = function (data) {
Expand All @@ -106,12 +106,12 @@ function BST() {
return currentNode.data;
}

const smallestNode = function (node) {
let currentNode = node;
while (!(currentNode.left === null)) {
currentNode = currentNode.left;
}
return currentNode;
const smallestNode = function (currentNode) {
const result = (function minNode(currentNode) {
if(currentNode.left === null) return currentNode;
return minNode(currentNode.left);
})(this.root);
return result;
}

this.remove = function(data) {
Expand Down
2 changes: 1 addition & 1 deletion test/binarySearchTree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('BST method', () => {
});
it('finds the smallest value', () => {
let myBST = new BST();
myBST.insert(47);
myBST.insert(47);
myBST.insert(23);
myBST.insert(2);
myBST.insert(4);
Expand Down

0 comments on commit 9ae5813

Please sign in to comment.