This is a basic algorithm that creates change with the smallest number of coins. How can this be better written? It works perfectly, but I just imagine there is a cleaner and shorter version of this.
const generateCoinChange = cents => {
let quarter = 0;
let dime = 0;
let nickel = 0;
let penny = 0;
let remainingChange = cents;
while (remainingChange >= 25) {
remainingChange -= 25;
quarter++;
}
while (remainingChange >= 10) {
remainingChange -= 10;
dime++;
}
while (remainingChange >= 5) {
remainingChange -= 5;
nickel++;
}
while (remainingChange > 0) {
remainingChange -= 1;
penny++;
}
console.log(`Quarters: ${quarter}, Dimes: ${dime}, Nickels: ${nickel}, Pennies: ${penny}`)
};
generateCoinChange(94);
generateCoinChange(100);
generateCoinChange(23);