Skip to content

Instantly share code, notes, and snippets.

@risingBirdSong
Created December 29, 2019 03:35
Show Gist options
  • Save risingBirdSong/de7d392a9c5964d3ccf42d4307e4aad8 to your computer and use it in GitHub Desktop.
Save risingBirdSong/de7d392a9c5964d3ccf42d4307e4aad8 to your computer and use it in GitHub Desktop.
const coinCombo = function(cents : number) {
let change : [penny, nickel, dime, quarter] = [0,0,0,0];
let quarters, dimes, nickels, pennies;
if (cents / 25 >= 1) {
quarters = Math.floor(cents / 25);
cents -= 25 * quarters;
}
if (cents / 10 >= 1) {
dimes = Math.floor(cents / 10)
cents -= 10 * dimes;
}
if (cents / 5 >= 1) {
nickels = Math.floor(cents / 5);
cents -= 5 * nickels;
}
return [cents || 0, nickels || 0, dimes || 0, quarters]
}
coinCombo(56) //?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment