Last active
August 14, 2019 12:40
-
-
Save gatarelib/35d8bb41e6d33bb5be694e5db70e79d0 to your computer and use it in GitHub Desktop.
Andela assessment
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
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; | |
} | |
} |
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
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