Skip to content

Instantly share code, notes, and snippets.

View MichaelWalker-git's full-sized avatar

Michael Walker MichaelWalker-git

View GitHub Profile
@MichaelWalker-git
MichaelWalker-git / gist:013d76334b659c36a8cec72fce1860a8
Created April 5, 2016 22:38 — forked from TessMyers/gist:a252520dd9a8fe68f8e5
Simple exercises using .map and .reduce
// Simple problems to solve using the native .reduce and .map array methods. Each of these problems can be solved in many
// different ways, but try to solve them using the requested higher order function.
// MAP
// Write a function capitalize that takes a string and uses .map to return the same string in all caps.
// ex. capitalize('whoop') // => 'WHOOP'
// ex. capitalize('oh hey gurl') // => "OH HEY GURL"
var capitalize = function(string){
// code code code!
@MichaelWalker-git
MichaelWalker-git / The Technical Interview Cheat Sheet.md
Created October 11, 2016 20:53 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
function tapeEquilibrium(A) {
var p, i;
var leftSum = 0, rightSum = 0;
var totalSum = 0;
var lastMin, currentMin;
var leng = A.length;
if (leng == 2) { return Math.abs(A[0] - A[1]); }
if (leng == 1) { return Math.abs(A[0]); }
//edge cases where the length is 1 or 2
function solution(A) {
var min = 1;
A.sort(function(a,b){
// Sort the array explicit way
return a - b;
});
for (var i in A) {
if (A[i] > -1 && A[i] == min) {
min++;
/*
You are given N counters, initially set to 0, and you have two possible operations on them:
• increase(X) − counter X is increased by 1,
• max counter − all counters are set to the maximum value of any counter.
A non-empty zero-indexed array A of M integers is given. This array represents consecutive operations:
• if A[K] = X, such that 1 ≤ X ≤ N, then operation K is increase(X),
• if A[K] = N + 1 then operation K is max counter.
function prefixSums(A){
var leng = A.length;
p = [0] * (leng +1);
for(var i = 0; i< leng+1; i++){
P[i] = P[i-1] + A[i-1];
}
return P;
}
Given non empty, zero indexed array (A)
A has n integers (1 < n < 100000)
A represents number of mushrooms growing in a consecutive spots along the road
Given integers k and m
k = spot on the road and m = number of moves
In one move, she moves to an adjacent spot
function solution(X, A) {
// write your code in JavaScript (Node.js 0.12)
var count = new Array(X);
for ( var i=0; i < A.length; i++) {
var info = {
minute : i,
count : 1
};
function oneArray(arr) {
return arr.reduce(function (first, next) {
return first.concat(Array.isArray(next) ? oneArray(next) : next);
}, []);
}
oneArray([[1,2,[3]],4]);
let map = new Map();
map.set("a", 1);
map.set("b", 2);
map.set("c", 3);
let obj = Array.from(map).reduce((obj, [key, value]) => (
Object.assign(obj, { [key]: value }) // Be careful! Maps can have non-String keys; object literals can't.
), {});
console.log(obj); // => { a: 1, b: 2, c: 3 }