Skip to content

Instantly share code, notes, and snippets.

View pporche87's full-sized avatar

Patrick Porche pporche87

View GitHub Profile
export default class DirectedGraph {
constructor() {
this._nodes = {}
this._count = 0
}
addVertex(value) {
if (value === undefined) return
this._nodes[value] = this._nodes[value] || []
this._count++
visit(vertex, callback) {
// create an array "visited" to track keys of the verticies that you have seen
const visited = []
// create a function "recurseivelyVisit" that:
const recurseivelyVisit = (vertexKey) => {
// - takes a vertex key as a parameter
// - calls the callback for that vertex
callback(vertexKey)
// - marks that vertex as visited
visited.push(vertexKey)
import chai, { expect } from 'chai'
import chaiChange from 'chai-change'
import TreeNode from '../../src/advanced/TreeNode'
chai.use(chaiChange)
describe('TreeNode', () => {
it('exists', () => {
expect(TreeNode).to.be.a('function')
export default class TreeNode {
constructor(data, left, right) {
this.data = data
this.left = null
this.right = null
}
getData() {
return this.data
}
import chai, { expect } from 'chai'
import chaiChange from 'chai-change'
import BinarySearchTree from '../../src/advanced/BinarySearchTree'
chai.use(chaiChange)
describe('BinarySearchTree', () => {
it('exists', () => {
expect(BinarySearchTree).to.be.a('function')
import TreeNode from './treeNode'
export default class BinarySearchTree {
constructor() {
this.root = null
this.count = 0
}
insert(value) {
const root = this.root
import chai, { expect } from 'chai'
import chaiChange from 'chai-change'
import HashTable from '../../src/advanced/hashTable'
chai.use(chaiChange)
describe('HashTable', () => {
it('exists', () => {
expect(HashTable).to.be.a('function')
import { Node, LinkedList } from './linkedListHashTable'
export default class HashTable {
constructor() {
this.storage = {}
this.count = 0
}
hash(key) {
if (typeof key === 'string') {
class Node {
constructor(key, value) {
this.key = key
this.value = value
this.next = null
}
}
class LinkedList {
constructor() {
import { expect } from 'chai';
import setUnion from '../src/setUnion';
describe('setUnion()', () => {
it('should be a function', () => {
expect(setUnion).to.be.a('function');
});
it('Return the union of two sets.', () => {
const firstSet = [1, 2, 3, 4];