Skip to content

Instantly share code, notes, and snippets.

View notshekhar's full-sized avatar
💜
Machine learning

Shekhar Tyagi notshekhar

💜
Machine learning
View GitHub Profile
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
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)
//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);
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}`
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 {
//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])
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()