Skip to content

Instantly share code, notes, and snippets.

@gatarelib
Last active August 14, 2019 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gatarelib/35d8bb41e6d33bb5be694e5db70e79d0 to your computer and use it in GitHub Desktop.
Save gatarelib/35d8bb41e6d33bb5be694e5db70e79d0 to your computer and use it in GitHub Desktop.
Andela assessment
var countChange = function(money, coins) {
return findComboCount(money, coins, 0);
}
function findComboCount(money, coin, index) {
if(money === 0){
return 1;
}
else if (money < 0 || coin.length == index) {
return 0;
}
else {
var withFirstCoin = findComboCount(money - coin[index], coin, index);
var withoutFirstCoin = findComboCount(money, coin, index + 1);
return withFirstCoin + withoutFirstCoin;
}
}
let assert = require("chai").assert;
describe('Challenge', function() {
it('should handle the example case', function() {
assert.equal(countChange(4,[1,2]), 3);
});
it('should handle another simple case', function() {
assert.equal(countChange(10,[5,2,3]), 4);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment