Skip to content

Instantly share code, notes, and snippets.

@conste11ations
conste11ations / authContext.js
Created December 1, 2021 05:24
Auth context SSR
import { createContext } from "react";
const authContext = createContext({
authenticated: false,
setAuthenticated: (auth) => {}
});
export default authContext;
class BinaryNode {
constructor(number) {
this.number = number;
this.left = null;
this.right = null;
}
}
@conste11ations
conste11ations / bucketSort.js
Last active April 11, 2020 03:06 — forked from mitrakmt/bucketSort.js
Exploring bucket sort in JavaScript.
// InsertionSort to be used within bucket sort
function insertionSort(array) {
var length = array.length;
for(var i = 1; i < length; i++) {
var temp = array[i];
for(var j = i - 1; j >= 0 && array[j] > temp; j--) {
array[j+1] = array[j];
}
array[j+1] = temp;
@conste11ations
conste11ations / HashTable.js
Created April 10, 2020 05:29 — forked from alexhawkins/HashTable.js
Correct Implementation of a Hash Table in JavaScript
var HashTable = function() {
this._storage = [];
this._count = 0;
this._limit = 8;
}
HashTable.prototype.insert = function(key, value) {
//create an index for our storage location by passing it through our hashing function
var index = this.hashFunc(key, this._limit);
class HashTable {
constructor() {
this.table = new Array(137);
this.values = [];
}
// Defining the hashing function which allows a sting to be used as a key
hash(string) {
const H = 37;
let total = 0;
@conste11ations
conste11ations / minHeap.js
Created April 7, 2020 03:12 — forked from tpae/minHeap.js
JavaScript implementation of Min Heap Data Structure
// Implement a min heap:
// -> insert, extract_min
// property:
// - elements are in ascending order
// - complete binary tree (node is smaller than it’s children)
// - root is the most minimum
// - insert takes O(logn) time
// - insert to the bottom right
@conste11ations
conste11ations / Trie.js
Created April 6, 2020 02:17 — forked from tpae/Trie.js
Trie.js - super simple JavaScript implementation
// Trie.js - super simple JS implementation
// https://en.wikipedia.org/wiki/Trie
// -----------------------------------------
// we start with the TrieNode
function TrieNode(key) {
// the "key" value will be the character in sequence
this.key = key;