Skip to content

Instantly share code, notes, and snippets.

@adyngom
Created June 1, 2019 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adyngom/16f26bfca4fb39a136e9cf49c6fef215 to your computer and use it in GitHub Desktop.
Save adyngom/16f26bfca4fb39a136e9cf49c6fef215 to your computer and use it in GitHub Desktop.
exercise solution for the rolls challenge
import { coinsJar } from './oneKCoins';
import { displayRollsMessage, getQuotientRemainder, groupBy } from './Utils';
const coinRolls = { "1": 50, "5": 40, "10": 50, "25": 40 };
const coinLabels = {
"1": "Pennies",
"5": "Nickels",
"10": "Dimes",
"25": "Quarters"
};
const coinsCount = coinsJar.reduce(groupBy, {});
const coinsInfo = Object.keys(coinsCount).map(key => {
const totalCoins = coinsCount[key];
const rollCount = coinRolls[key];
const label = coinLabels[key];
const { quotient, remainder } = getQuotientRemainder(totalCoins, rollCount);
const coinInfo = { label, quotient, remainder };
return coinInfo;
});
console.log(coinsInfo.map(displayRollsMessage).join("\n"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment