Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rolls of Coins - JavaScript Code Challenge

Rolls of Coins - JavaScript Code Challenge

Rolls of Coins is the fourth challenge in the "28 Relevant JavaScript Interview Questions" series. In this step by step approach, I share one the ways to attack a code challenge in a context of an onsite interview.

"At the end of her shift, Amina’s tip jar is full of coins. She needs a little help in counting and stocking her hard earned loot. She wants to organize her coins in rolls so it is easy to bring back to the bank.

Write a program that will help her quickly find out how many rolls she has for each coin denomination and the remainder on each.

Your program will accept an unsorted array of coins. You can assume that each coin will be either 1, 5, 10 or 25. It should print a message like the one below:

Pennies:10 rolls - 39 left
Nickels: 25 rolls - 0 left
Dimes: 12 rolls - 49 left
Quarter: 2 rolls - 20 left".

PLEASE NOTE:
If you are following along or reading the code please know that the first line of the function getQuotientRemainder is wrong and should instead throw an error. This has been fixed in the github repo of this presentation:

function getQuotientRemainder(x, y) {
if (!y) {
// will catch falsey values: 0, false, null, '', "", ``, undefined
throw new Error('we need an x value and a y value');
}
return { quotient: parseInt(x / y), remainder: x % y };
}

Avatar for Ady Ngom

Ady Ngom

June 01, 2019
Tweet

Other Decks in Technology

Transcript

  1. www.adyngom.com #4 - Rolls of c ins At the end

    of her shift, Amina’s tip jar is full of coins. She needs a little help in counting and stocking her hard earned loot. She wants to organize her coins in rolls so it is easy to bring back to the bank. Write a program that will help her quickly find out how many rolls she has for each coin denomination and the remainder on each.
  2. www.adyngom.com #4 - Rolls of c ins Below is a

    table of how many coins should be in each roll per denomination: COINS COINS PER ROLL VALUE PENNY ==> 1 50 $0.50 NICKEL ==> 5 40 $2.00 DIME ==> 10 50 $5.00 QUARTER ==> 25 40 $10.00
  3. www.adyngom.com #4 - Rolls of c ins Your program will

    accept an unsorted array of coins. You can assume that each coin will be either 1, 5, 10 or 25. It should print a message like the one below: PENNIES 10 ROLLS 39 LEFT NICKELS 25 ROLLS 0 LEFT DIMES 12 ROLLS 49 LEFT QUARTERS 2 ROLLS 20 LEFT
  4. www.adyngom.com I have always been a big advocate of explaining

    complex concepts in simple terms. This was at the core of the different Front-end related meetups I use to run in San Francisco CA. I'm first and foremost a learner at heart. I really shy away from the word expert, but Javascript and the ecosystem of libraries and frameworks around it have been my passion and work for the last 15 years. I hope that you will carve a space in your busy digital lives and join me in this great learning journey. JavaScript is your best bet A D Y N G O M - U I A R C H I T E C T - J S P A S S I O N A T E @adyngom