Created
June 1, 2019 16:38
-
-
Save adyngom/16f26bfca4fb39a136e9cf49c6fef215 to your computer and use it in GitHub Desktop.
exercise solution for the rolls challenge
This file contains 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
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