Skip to content

Instantly share code, notes, and snippets.

View dengjonathan's full-sized avatar

Jon Deng dengjonathan

View GitHub Profile
@dengjonathan
dengjonathan / jobSearch.js
Created February 16, 2017 18:53
dengjonathan
/*
You have a defined set of activities you can be doing during your job search
process. Each activity has a cost (time that it takes you to complete the activity)
and each activity provides some value (XP, or experience points,
that will increase your chances of finding a job).
Write a function that maximizes XP for a given input of time. Try to make your
solution as efficient as possible.
*/
@dengjonathan
dengjonathan / stopwatch.js
Created February 15, 2017 01:12
redux middleware example
const redux = require('redux');
const reducer = (state={}, action) => {
switch(action.type) {
case 'START':
return Object.assign({}, state, {start: Date.now(), interval: action.interval});
case 'TICK':
return Object.assign({}, state, {elapsed: action.currentTime - state.start});
case 'STOP':
return Object.assign({}, state, {interval: null});
@dengjonathan
dengjonathan / jobSearchDP.js
Created February 10, 2017 01:07
job search DP solution
const ACTIVITIES = [
{name: 'side-project', time: 10, xp: 12},
{name: 'algorithms', time: 3, xp: 7},
{name: 'networking', time: 1, xp: 0.5},
{name: 'exercise', time: 2, xp: 1.5},
{name: 'systems design', time: 4, xp: 4},
{name: 'making CSS codepens', time: 3, xp: 4}
];
/**
@dengjonathan
dengjonathan / jobSearchBackTrack.js
Created February 9, 2017 16:08
job Search backtracking solution
const ACTIVITIES = [
{name: 'side-project', time: 10, xp: 12},
{name: 'algorithms', time: 3, xp: 7},
{name: 'networking', time: 1, xp: 0.5},
{name: 'exercise', time: 2, xp: 1.5},
{name: 'systems design', time: 4, xp: 4},
{name: 'making CSS codepens', time: 3, xp: 4}
];
/**
@dengjonathan
dengjonathan / jobSearchBackTrack.js
Created February 9, 2017 16:03
Job Search backtracking
const ACTIVITIES = [
{name: 'side-project', time: 10, xp: 12},
{name: 'algorithms', time: 3, xp: 7},
{name: 'networking', time: 1, xp: 0.5},
{name: 'exercise', time: 2, xp: 1.5},
{name: 'systems design', time: 4, xp: 4},
{name: 'making CSS codepens', time: 3, xp: 4}
];
/**
@dengjonathan
dengjonathan / jobSearchLinear.js
Created February 8, 2017 18:19
Job Search Brute force
const ACTIVITIES = [
{name: 'side-project', time: 10, xp: 12},
{name: 'algorithms', time: 3, xp: 7},
{name: 'networking', time: 1, xp: 0.5},
{name: 'exercise', time: 2, xp: 1.5},
{name: 'systems design', time: 4, xp: 4},
{name: 'making CSS codepens', time: 3, xp: 4}
];
/**
@dengjonathan
dengjonathan / jobSearchLinear.js
Created February 8, 2017 18:18
Find Job Brute Force
const ACTIVITIES = [
{name: 'side-project', time: 10, xp: 12},
{name: 'algorithms', time: 3, xp: 7},
{name: 'networking', time: 1, xp: 0.5},
{name: 'exercise', time: 2, xp: 1.5},
{name: 'systems design', time: 4, xp: 4},
{name: 'making CSS codepens', time: 3, xp: 4}
];
/**
@dengjonathan
dengjonathan / jobSearchLinear.js
Created February 8, 2017 18:09
Job Search Brute Force
const ACTIVITIES = [
{name: 'side-project', time: 10, xp: 12},
{name: 'algorithms', time: 3, xp: 7},
{name: 'networking', time: 1, xp: 0.5},
{name: 'exercise', time: 2, xp: 1.5},
{name: 'systems design', time: 4, xp: 4},
{name: 'making CSS codepens', time: 3, xp: 4}
];
/**
@dengjonathan
dengjonathan / jobSearch.js
Created February 5, 2017 16:17
job search knpasack
/*
You have a defined set of activities you can be doing during your job search
process. Each activity has a cost (time that it takes you to complete the activity)
and each activity provides some value (XP, or experience points, that will increase your chances of finding a job).
Write a function that maximizes XP for a given input of time. Try to make your
solution as efficient as possible.
*/
const ACTIVITIES = [
@dengjonathan
dengjonathan / ex4.js
Created January 31, 2017 22:32
Sequenced async calls using promises
function fakeAjax(url,cb) {
var fake_responses = {
"file1": "The first text",
"file2": "The middle text",
"file3": "The last text"
};
var randomDelay = (Math.round(Math.random() * 1E4) % 8000) + 1000;
console.log("Requesting: " + url);