Another javascript solution:
function change(money) { let coins = [1, 5, 10, 25]; let parts = new Map([[25, 0],[10,0],[5,0],[1,0]]); let currentCoin = coins.pop(); while(coins.length > 0) { if(money < currentCoin) { currentCoin = coins.pop(); } else { parts.set(currentCoin, parts.get(currentCoin)+1); money -= currentCoin; } } return parts; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Another javascript solution: