Created
August 28, 2020 18:44
-
-
Save juelvaldivia/10a305bba165eeacf37fd4457c82d5fc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 hitTheLottery(amountToWithdraw) { | |
// denominaciones de billetes | |
const denominations = [1, 5, 10, 20, 100] | |
// declaracion de variables dinero entregado y billetes en 0 | |
let delivered = 0; | |
let bills = 0; | |
// se ordenan las denominaciones en orden descendente | |
denominations.sort((prev, current)=> current - prev); | |
// recorre cada denominacion | |
denominations.forEach(denomination => { | |
// se resta lo entregado al monto a retirar | |
const toDelivered = (amountToWithdraw-delivered) | |
// realiza division de la cantidad a retirar entre la denominacion | |
// para obtener el total de billetes por denominacion | |
const billsForDenomination = parseInt(toDelivered / denomination) | |
// suma los billetes por denominacion | |
bills+=billsForDenomination | |
// multiplica la denominacion por los billetes a entregar | |
// para sumar la cantidad entregada | |
delivered+=(denomination*billsForDenomination) | |
}) | |
// regresa el total de billetes por entregar | |
return bills; | |
} | |
const amount = 43; | |
const totalBills = hitTheLottery(amount) | |
console.log(totalBills) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment