Rob Levin
1 min readJun 10, 2019

--

This was fun! I challenged myself to do them in chrome console (haha, shift-enter galore).

const calculate = (coins) => {
if (!coins || !coins.length) return null;
const pennies = [];
const nickels = [];
const dimes = [];
const quarters = [];
coins.map(coin => {
switch(coin) {
case 1:
pennies.push(coin);
break;
case 5:
nickels.push(coin);
break;
case 10:
dimes.push(coin);
break;
case 25:
quarters.push(coin);
break;
default:
console.warn("Coins must be penny, nickel, dime, or quarter");
}
});
console.log(`Pennies: ${Math.floor(pennies.length/50)} rolls—${pennies.length%50} left`);
console.log(`Nickels: ${Math.floor(nickels.length/40)} rolls—${nickels.length%40} left`);
console.log(`Dimes: ${Math.floor(dimes.length/50)} rolls—${dimes.length%50} left`);
console.log(`Quarter: ${Math.floor(quarters.length/40)} rolls—${quarters.length%40} left`);
}

Then, since I was in console, I was like “hrm, I need to generate some test data…” which was also an interesting challenge:

var arr = [];
var possibles = [1,5,10,25];
for (let i=0; i<2000; i++) {
arr.push(possibles[Math.floor(Math.random() * possibles.length)]);
}

Letting me do:

calculate(arr)
Pennies: 10 rolls—36 left
Nickels: 12 rolls—12 left
Dimes: 9 rolls—33 left
Quarter: 12 rolls—9 left

I also enjoyed the partial application questions and did in console as well. Assuming the base function already implemented, I presume you were looking for something like: const associateCalc = (hours, ovtHours) => baseFunction.call(null, associate, hours, ovtHours) for the partial applications no?

When you do these interviews do you ask them to white board it or do they get to use a laptop or something? I found myself doing silly things like putting the log statements in a loop and then correcting haha :)

Looking forward to reading the part in the series!

--

--

Responses (2)