Skip to content

Instantly share code, notes, and snippets.

@Jiert
Last active August 29, 2015 14:20
Show Gist options
  • Save Jiert/742e9fe707c466a62d13 to your computer and use it in GitHub Desktop.
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
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;
}
@Jiert
Copy link
Author

Jiert commented Aug 25, 2015

Wow, did I write this? I kinda like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment