-
-
Save parzibyte/4e6594c0644b97b4ec517440c6a86eb4 to your computer and use it in GitHub Desktop.
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
const dineroAMonedas = (cantidad, monedas) => { | |
/* | |
https://parzibyte.me/blog | |
*/ | |
// Primero ordenamos las monedas de mayor a menor: | |
// https://parzibyte.me/blog/2018/10/28/ordenar-arreglos-javascript-sort/#Ordenar_arreglo_de_enteros_ascendente | |
monedas.sort((unNumero, otroNumero) => otroNumero - unNumero); | |
const monedasUsadas = []; | |
for (const moneda of monedas) { | |
while (cantidad >= moneda) { | |
monedasUsadas.push(moneda); | |
cantidad -= moneda; | |
} | |
} | |
return monedasUsadas; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment