This file contains hidden or 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
| export default class DirectedGraph { | |
| constructor() { | |
| this._nodes = {} | |
| this._count = 0 | |
| } | |
| addVertex(value) { | |
| if (value === undefined) return | |
| this._nodes[value] = this._nodes[value] || [] | |
| this._count++ |
This file contains hidden or 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
| 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) |
This file contains hidden or 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
| 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') |
This file contains hidden or 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
| export default class TreeNode { | |
| constructor(data, left, right) { | |
| this.data = data | |
| this.left = null | |
| this.right = null | |
| } | |
| getData() { | |
| return this.data | |
| } |
This file contains hidden or 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
| 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') |
This file contains hidden or 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
| import TreeNode from './treeNode' | |
| export default class BinarySearchTree { | |
| constructor() { | |
| this.root = null | |
| this.count = 0 | |
| } | |
| insert(value) { | |
| const root = this.root |
This file contains hidden or 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
| 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') |
This file contains hidden or 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
| import { Node, LinkedList } from './linkedListHashTable' | |
| export default class HashTable { | |
| constructor() { | |
| this.storage = {} | |
| this.count = 0 | |
| } | |
| hash(key) { | |
| if (typeof key === 'string') { |
This file contains hidden or 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 Node { | |
| constructor(key, value) { | |
| this.key = key | |
| this.value = value | |
| this.next = null | |
| } | |
| } | |
| class LinkedList { | |
| constructor() { |
This file contains hidden or 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
| 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]; |