UNPKG

ds-algo-study

Version:

Just experimenting with publishing a package

12 lines (10 loc) 480 B
let countChange = function ( money, coins ) { function countChangeSub ( money, coins, n ) { if ( money == 0 ) return 1; if ( money < 0 || coins.length == n ) return 0; let countSubArr = countChangeSub( money - coins[ n ], coins, n ) + countChangeSub( money, coins, n + 1 ); return countSubArr; } return countChangeSub( money, coins, 0 ); } console.log( 'countChange(23,[1,2,5]): ', countChange( 23, [ 1, 2, 5 ] ) );//countChange(23,[1,2,5]): 36