/************************************************Hello! This is a playground for binary trees.Write JavaScript here, then click the "Run" buttonto step through your code. On the right hand side,you'll see any trees that are in scope.For it to work, you must build your trees usingthe provided TreeNode constructor. You can alsouse the convenience buildTree function. See thecode below for usage.Note: this is an alpha version, and a lot of thingsdon't work. Notably, only one binary tree at a timewill be displayed.The code is on GitHub:http://github.com/kasrak/treevis************************************************/function binarySearch(node, value) {
if (!node || node.value == value) {
return node;
} else if (node.value < value) {
return binarySearch(node.right, value);
} else {return binarySearch(node.left, value);
}
}
function addNode(tree, value) {
if (!tree) {
return TreeNode(value);
} else if (tree.value < value) {
tree.right = addNode(tree.right, value);
} else {tree.left = addNode(tree.left, value);
}
return tree;
}
var root = buildTree([10, [5, [2], [7]],