This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const EventEmitter = require("events").EventEmitter; | |
| class Pizza extends EventEmitter { | |
| constructor(size = 1) { | |
| super(); | |
| this.ovenTime = this._ovenTime(size); | |
| this.maxIngredients = this._maxIngredients(size); | |
| this.ingredients = []; | |
| this.timeToReleasePizza = 5; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| find(node, key) { | |
| if (node === null) return null; | |
| else if (key < node.key) return this.find(node.left, key); | |
| else if (key > node.key) return this.find(node.right, key); | |
| else return node; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| levelOrder() { | |
| if (!this.root) return []; | |
| var array = []; | |
| search(this.root, 1, 1); | |
| function search(node, level, index) { | |
| if (node) { | |
| const count = Math.pow(2, level - 1); | |
| if (array.length < level) { | |
| array.push(Array(count).fill("")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| postorder(node, fn) { | |
| if (node !== null) { | |
| this.postorder(node.left, fn); | |
| this.postorder(node.right, fn); | |
| fn(node); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| preorder(node, fn) { | |
| if (node !== null) { | |
| fn(node); | |
| this.preorder(node.left, fn); | |
| this.preorder(node.right, fn); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inorder(node, fn) { | |
| if (node !== null) { | |
| this.inorder(node.left, fn); | |
| fn(node); | |
| this.inorder(node.right, fn); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| remove(key) { | |
| if (!Number.isInteger(key)) return; | |
| this.root = this.removeNode(this.root, key); | |
| } | |
| removeNode(node, key) { | |
| if (node === null) return null; | |
| else if (key < node.key) { | |
| node.left = this.removeNode(node.left, key); | |
| return node; | |
| } else if (key > node.key) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| insert(key, value) { | |
| if (!Number.isInteger(key)) return; | |
| const newNode = new BinaryNode(key, value); | |
| if (this.root === null) this.root = newNode; | |
| else this.insertNode(this.root, newNode); | |
| } | |
| insertNode(node, newNode) { | |
| if (newNode.key < node.key) { | |
| if (node.left === null) node.left = newNode; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BinaryNode { | |
| constructor(key, value) { | |
| this.value = value; | |
| this.key = key; | |
| this.left = null; | |
| this.right = null; | |
| } | |
| // Cost: O(1) | |
| free() { | |
| this.left = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Team { | |
| constructor(name, zone){ | |
| this.zone = zone; | |
| this.name = name; | |
| } | |
| } | |
| class Game { | |
| constructor (team1, team2, week){ | |
| this.team1 = team1; |
NewerOlder