Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const coins = {
- 'penny': 1,
- 'nickel': 5,
- 'dime': 10,
- 'quarter': 25
- }
- const coinsByAmount = Object.keys(coins).reverse();
- function getChange(amount) {
- let change = [];
- for(let coinType of coinsByAmount) {
- let coinValue = coins[coinType];
- while(amount >= coinValue) {
- change.push(coinType);
- amount -= coinValue;
- }
- }
- return change;
- }
Add Comment
Please, Sign In to add comment