coin change problem all combinations javascript

Solutions on MaxInterview for coin change problem all combinations javascript by the best coders in the world

showing results for - "coin change problem all combinations javascript"
Lucian
21 Apr 2018
1var makeChange = function(total){
2  var count = 0;
3  var coins = [1, 2, 5, 10, 20, 50, 100, 200];
4
5  var changer = function(index, value){
6
7    var currentCoin = coins[index];
8
9    if( index === 0){
10      if( value % currentCoin === 0){
11        count++;
12      }
13      return;
14    }
15
16    while( value >= 0 ){
17      changer(index-1, value);
18      value -= currentCoin;
19    }
20  }
21  changer(coins.length-1, total);
22  return count;
23};
24
25makeChange(200);