This file contains 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
function Point(x, y) { | |
this.x = x | |
this.y = y | |
} | |
function Boundary(x, y, x2, y2) { | |
this.x = x | |
this.y = y | |
this.x2 = x2 | |
this.y2 = y2 |
This file contains 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
function HashTable(object, size) { | |
this.length = size || 1 | |
this._ = new Array(this.length) | |
this.size = 0 | |
const hash = function (key) { | |
let h = 1 | |
let keyLength = key.length | |
for (let i = 0; i < keyLength; i++) { | |
h += key.charCodeAt(i) |
This file contains 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
//Ineterval control | |
class Interval{ | |
constructor(fn, time){ | |
this.fn = fn | |
this.time = time | |
this.timer = false; | |
} | |
start() { | |
if (!this.isRunning()) | |
this.timer = setInterval(this.delayfn, this.delaytime); |
This file contains 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 $ = function (selector) { | |
if (typeof selector == "string" || selector instanceof String) | |
return new Element(...document.querySelectorAll(selector)) | |
else return new Element(selector) | |
} | |
$.get = function ({ url, data = {}, success = () => {} }) { | |
const queryString = Object.entries(data) | |
.map(([key, value]) => { | |
return `${key}=${value}` |
This file contains 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 vector { | |
constructor(x, y, z) { | |
this.x = x || 0 | |
this.y = y || 0 | |
this.z = z || 0 | |
} | |
add(a) { | |
if (a instanceof vector) { | |
return new vector(this.x + a.x, this.y + a.y, this.z + a.z) | |
} else { |
This file contains 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
//function to reshape the array | |
Array.prototype.reshape = function (rows, cols) { | |
var copy = this.slice(0) // Copy all elements. | |
this.length = 0 // Clear out existing array. | |
for (var r = 0; r < rows; r++) { | |
var row = [] | |
for (var c = 0; c < cols; c++) { | |
var i = r * cols + c | |
if (i < copy.length) { | |
row.push(copy[i]) |
This file contains 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
function Node() { | |
this.values = null | |
this.end = false | |
this.add = (v, t) => { | |
if (!this.values) this.values = {} | |
if (!this.values[v]) this.values[v] = new Node() | |
} | |
} | |
function Trees() { | |
this.root = new Node() |