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
const noop = () => void 0; | |
function Covenant(fn) { | |
this.resolver = fn; | |
this.thenCallback = noop; | |
this.catchCallback = noop; | |
this.resolver((...args) => { | |
this.thenCallback(...args); | |
}, () => { |
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
function jayquery(selector) { | |
const elements = document.querySelectorAll(selector); | |
return { | |
bgcolor: function(value) { | |
elements.forEach(element => element.style.background = value); | |
return this; | |
}, | |
text: function(value) { | |
elements.forEach(element => element.innerText = 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
function randy() { | |
return Math.random(); | |
} | |
function smoke() { | |
return "poof"; | |
} | |
function depend(dependencies, fn) { | |
fn.apply(null, dependencies.map(dep => window[dep])); |
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
function permute(arr, permutation=[], permutations=[]) { | |
if(arr.length === 0) { | |
permutations.push(permutation); | |
}else { | |
arr.forEach(item => { | |
permute(arr.filter(value => value != item), permutation.concat(item), permutations); | |
}); | |
} | |
return permutations; |
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
//https://www.hackerrank.com/challenges/ctci-recursive-staircase | |
function stairStepper(stepSizes) { | |
let answers = [1,1]; | |
return function(numSteps) { | |
if(numSteps < 0) { | |
return 0; | |
}else if(typeof answers[numSteps] === 'undefined') { | |
answers[numSteps] = stepSizes.reduce((totalSteps, stepSize) => totalSteps + stairCombinations(numSteps-stepSize), 0); | |
} |
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
// A prime number is a natural number that has exactly two distinct natural number divisors: 1 and itself. | |
const isPrime = (function () { | |
let primes = {}; | |
let notPrimes = {}; | |
return function (number) { | |
if(primes[number]) return true; | |
if(number === 1 || notPrimes[number]) return 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
function merge(arrA, arrB) { | |
let idxA=0, idxB=0, result=[]; | |
while(idxA < arrA.length || idxB < arrB.length) { | |
if(idxB === arrB.length || arrA[idxA] <= arrB[idxB]) { | |
result.push(arrA[idxA]); | |
idxA++; | |
}else if(idxA === arrA.length || arrB[idxB] <= arrA[idxA]) { | |
result.push(arrB[idxB]); |
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
// https://www.hackerrank.com/challenges/ctci-find-the-running-median | |
let input = `6 | |
12 | |
4 | |
5 | |
3 | |
8 | |
7`; |
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
// https://www.hackerrank.com/challenges/ctci-contacts | |
function Trie() { | |
this.data = {}; | |
} | |
Trie.prototype.process = function(op, str) { | |
if(op === 'add') { | |
let data = 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
// https://www.hackerrank.com/challenges/ctci-ice-cream-parlor | |
// find 2 distinct flavors that would take up all of the money m | |
// for each trip print the id numbers of the two types of ice cream | |
// some ice creams may have the same price | |
function purchase(indexed, product) { | |
let result = Object.assign({}, indexed); |