BST
Binary Search Tree
Why BST?
Why BST?
BinarySearchTree.prototype.contains = function(v) {
return this.traverse().includes(v); // or indexOf
}
//...
BinarySearchTree.prototype.traverse = function(direction) {
// get values array
if (!directon) {
return array.reverse();
}
}
Arrays
This vs Prototype
*.prototype.root
this.root = null;
Empty Tree
this.root()
function BinarySearchTree() {
this._root = null;
}
BinarySearchTree.prototype = function() {
if (this._root) {
return this._root;
}
}
//or...
function BinarySearchTree() {
this._root = new Node();
}
Node class
Node class
function Node(key, value) { ... }
Node.prototype.append = function() { ... }
Node.prototype.swap = function() { ... }
Node.prototype.MAGIC = function() { ... }
Magic strings!
Magic strings
BinarySearchTree.prototype.search = function(k) {
//logic here...
if (!value) {
return 'undefined';
}
}
var mySuperValue = bst.search(42);
var check = !!mySuperValue; // true
Magic strings
throw 'Not found!!1';
//...
throw Error('Not found');
Style
function ( var) {
this.append =null;
if(flag) throw 'AAAAAA!!1';
return undefined;
}
Console.log
and debugger of course
Custom tests
Global Scope
vs (function() { ... })()
Q&A part
BST workshop
By Uladzimir Halushka
BST workshop
- 505