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 Stack { | |
| constructor() { | |
| this._storage = {}; | |
| this._size = 0; | |
| } | |
| push(value) { | |
| this._size ++; | |
| this._storage[this._size] = value; | |
| } |
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 Queue { | |
| constructor() { | |
| this._start = 0; | |
| this._end = 0; | |
| this._storage = {}; | |
| } | |
| enqueue(value) { | |
| this._storage[this._end] = value; | |
| this._end ++; |
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
| var Hashtable = function() { | |
| this.storage = []; | |
| this.storageLimit = 8; | |
| }; | |
| Hashtable.prototype.insert = function(key, value) { | |
| var hash = getHash(key, this.storageLimit); | |
| this.storage[hash] = this.storage[hash] || []; | |
| var bucket = this.storage[hash]; | |
| var replaced = false; |
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
| // Suppose we could access yesterday's stock prices as an array, where: | |
| // | |
| // The indices are the time in minutes past trade opening time, which was 9:30am local time. | |
| // The values are the price in dollars of Apple stock at that time. | |
| // So if the stock cost $500 at 10:30am, stockPricesYesterday[60] = 500. | |
| // | |
| // Write an efficient function that takes stockPricesYesterday and returns the best profit I could have made from 1 purchase and 1 sale of 1 Apple stock yesterday. | |
| // | |
| // For example: | |
| // |
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
| var ns = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
| var biSearch = function(array, n, min, max){ | |
| if (min > max) { | |
| return -1; | |
| } | |
| var mid = Math.floor(min + max /2); | |
| if (n === array[mid]) { |
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
| // var stringifiableObjects = [ | |
| // 9, | |
| // null, | |
| // true, | |
| // false, | |
| // "Hello world", | |
| // [], | |
| // [8], | |
| // ["hi"], | |
| // [8, "hi"], |
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
| var $ = require('jquery')(require("jsdom").jsdom().parentWindow); | |
| var namesArray = []; | |
| var contributorArray = []; | |
| var contributor = []; | |
| $.ajax({ | |
| url: 'https://api.github.com/repos/18F/open-data-maker/contributors', | |
| dataType: 'json', |
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
| //http://www.udel.edu/CIS/181/pconrad/05S/examples/recursion/recursion.problems.html | |
| //Function that returns the sum of the digits of an integer. | |
| //876 = 8 + 7 + 6 = 21 | |
| var wrapper = function(num){ | |
| var digitsAdded = 0; | |
| var currentDigit = 0; |
NewerOlder