Guest User

Untitled

a guest
Oct 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. const coins = {
  2. 'penny': 1,
  3. 'nickel': 5,
  4. 'dime': 10,
  5. 'quarter': 25
  6. }
  7.  
  8. const coinsByAmount = Object.keys(coins).reverse();
  9.  
  10. function getChange(amount) {
  11. let change = [];
  12.  
  13. for(let coinType of coinsByAmount) {
  14. let coinValue = coins[coinType];
  15.  
  16. while(amount >= coinValue) {
  17. change.push(coinType);
  18. amount -= coinValue;
  19. }
  20. }
  21.  
  22. return change;
  23. }
Add Comment
Please, Sign In to add comment