Write a function countChange(amount, [...denominations]) that counts the number of ways you can make change for an amount of money, given an array of coin denominations.
For example, there are 3 ways to give change for 4 if you have coins with denomination 1 and 2:
1+1+1+1
1+1+2
2+2
The order of the coins doesn’t matter.
1+1+2 == 1+2+1 == 2+1+1
Also, assume you have an infinite amount of coins.
Your function should take an amount to change and an array of unique denominations for the coins.
countChange(4, [1, 2]) // will return 3
countChange(10, [2, 3, 5]) // will return 4
countChange(11, [5, 7]) // will return 0
Write a function
countChange(amount, [...denominations])
that counts the number of ways you can make change for an amount of money, given an array of coin denominations.For example, there are
3
ways to give change for4
if you have coins with denomination1
and2
:The order of the coins doesn’t matter.
Also, assume you have an infinite amount of coins.
Your function should take an amount to change and an array of unique denominations for the coins.