Skip to content

Instantly share code, notes, and snippets.

View jenjwong's full-sized avatar

Jen Wong jenjwong

  • Vancouver
View GitHub Profile
class Stack {
constructor() {
this._storage = {};
this._size = 0;
}
push(value) {
this._size ++;
this._storage[this._size] = value;
}
class Queue {
constructor() {
this._start = 0;
this._end = 0;
this._storage = {};
}
enqueue(value) {
this._storage[this._end] = value;
this._end ++;
@jenjwong
jenjwong / Hashtable
Created April 27, 2016 06:11
Hashtable
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;
@jenjwong
jenjwong / InterviewCake.txt
Last active October 20, 2018 18:18
Interview Cake: Stock Prices
// 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:
//
@jenjwong
jenjwong / gist:b321c57b43ffd9c2bb15
Last active January 19, 2017 00:42
Recursive Binary Serach
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]) {
// var stringifiableObjects = [
// 9,
// null,
// true,
// false,
// "Hello world",
// [],
// [8],
// ["hi"],
// [8, "hi"],
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',
@jenjwong
jenjwong / recursion.js
Last active October 26, 2015 06:27
Recursion: Add digits in Integer
//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;