Skip to content

Instantly share code, notes, and snippets.

View boxgames1's full-sized avatar
🏈
Over the scrimmage line

Oliver Alonso boxgames1

🏈
Over the scrimmage line
View GitHub Profile
@boxgames1
boxgames1 / observable-pattern-pizza.js
Last active April 22, 2022 06:40
Observable pattern - Pizza Maker
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;
}
@boxgames1
boxgames1 / BinaryTreeFind.js
Created June 29, 2018 12:45
BinaryTreeFind
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;
}
@boxgames1
boxgames1 / BinaryTreeLevelorder.js
Created June 29, 2018 11:25
BinaryTreeLevelorder
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(""));
@boxgames1
boxgames1 / BinaryTreePostorder.js
Created June 29, 2018 11:24
BinaryTreePostorder
postorder(node, fn) {
if (node !== null) {
this.postorder(node.left, fn);
this.postorder(node.right, fn);
fn(node);
}
}
@boxgames1
boxgames1 / BinaryTreePreorder.js
Last active June 29, 2018 11:25
BinaryTreePreorder
preorder(node, fn) {
if (node !== null) {
fn(node);
this.preorder(node.left, fn);
this.preorder(node.right, fn);
}
}
@boxgames1
boxgames1 / BinaryTreeInorder.js
Last active June 29, 2018 11:25
BinaryTreeInorder
inorder(node, fn) {
if (node !== null) {
this.inorder(node.left, fn);
fn(node);
this.inorder(node.right, fn);
}
}
@boxgames1
boxgames1 / BinaryTreeRemoval.js
Last active June 29, 2018 11:14
BinaryTreeRemoval
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) {
@boxgames1
boxgames1 / BinaryTreeInsertion.js
Created June 29, 2018 11:02
BinaryTreeInsertion
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;
@boxgames1
boxgames1 / BinaryNode.js
Created June 29, 2018 10:56
Binary Node
class BinaryNode {
constructor(key, value) {
this.value = value;
this.key = key;
this.left = null;
this.right = null;
}
// Cost: O(1)
free() {
this.left = null;
@boxgames1
boxgames1 / chocri_script.js
Created June 22, 2018 11:15
Chocri Script
class Team {
constructor(name, zone){
this.zone = zone;
this.name = name;
}
}
class Game {
constructor (team1, team2, week){
this.team1 = team1;