Last active
August 29, 2015 14:20
-
-
Save Jiert/742e9fe707c466a62d13 to your computer and use it in GitHub Desktop.
Coinify, find the lowest number of coins it would take to make X amount of cents
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
function coinify(cents){ | |
var count = parseInt(cents / 50), | |
leftOver = cents % 50, | |
coins = [25, 10, 5, 1], | |
iterator = 0; | |
while (leftOver > 0){ | |
count += parseInt( leftOver / coins[iterator] ); | |
leftOver = leftOver % coins[iterator]; | |
iterator ++; | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow, did I write this? I kinda like it.