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
// code pen url: https://codepen.io/jaspercreel/pen/RgXjEp | |
// Declaring a node and list class outside of the hash class avoids binding issues with this | |
// The node class should only be created with a key value pair | |
class Node { | |
constructor(key, value) { | |
this[key] = value; | |
this.next = null; | |
} |
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 LinkedList { | |
constructor() { | |
this.head = null; | |
this.tail = null; | |
this.count = 0; | |
} | |
get length() { | |
return this.count; | |
} |
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
/*HASH TABLE - a dictionary/hash map data structure for storing key/value pairs. Finding | |
an entry in a hash table takes O(1) constant time(same for 10 as 1 billion items). Whereas | |
finding an item via binary search takes time proportional to the logarithm of | |
the item in the list O(logn). Finding an item in a regular old list takes time proportional to | |
the length of the list O(n). Very slow. Hash Tables = very fast */ | |
var makeHashTable = function(max) { | |
var storage = [], | |
hashTableMethods = { |
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
var assert = require('assert'); | |
var LinkedStack = (function(){ | |
function Item(data){ | |
this.data = data; | |
this.next = null; | |
} | |
Item.prototype = { | |
tail: function(){ |