Last active
May 7, 2018 12:50
-
-
Save alexzobi/e3271431349c7e6adaa3fc4cb40c1a42 to your computer and use it in GitHub Desktop.
coins - recursive
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
function change(amount, coins, idx) { | |
if (idx >= coins.length -1) return 1; | |
let coin = coins[idx]; | |
let combos = 0; | |
for (let i=0; i * coin <= amount; i++){ | |
let amountRemaining = amount - i * coin; | |
console.log('i',i) | |
console.log('coin', coin) | |
console.log('remaining', amountRemaining) | |
combos += change(amountRemaining, coins, idx + 1); | |
console.log('combos', combos) | |
} | |
return combos; | |
} | |
change(25,[25,10,5,1],0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment