Created
July 21, 2016 00:36
-
-
Save zestime/464c8d46290a03a6f6b5a486a1f1a1e1 to your computer and use it in GitHub Desktop.
JavaScript ver. of Counting coins
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 countChange(money, coins) { | |
if (money == 0) return 1; | |
if (money < 0 || coins.length == 0) return 0; | |
return countChange(money - coins[0], coins) + countChange(money, coins.slice(1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment