Created
December 27, 2016 15:58
-
-
Save Arieg419/cdca8d2b8c17e68de2a6bd2e1a8b664f 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
function waysToReturnChange(denominations, numOfCoins, amount) { | |
if(amount === 0) return 1; // Perfect! | |
if(amount < 0) return 0; // No solution exists for negative amount | |
if(numOfCoins < 0 && amount > 0) return 0; // We don't have coins left! | |
console.log('checking ways to make ' + amount + ' with ' + denominations.slice(numOfCoins)); | |
return waysToReturnChange(denominations, numOfCoins, amount - denominations[numOfCoins]) + | |
waysToReturnChange(denominations, numOfCoins - 1, amount); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment