I am white boarding on how to solve Coin/Change Problem. Given a set of coins (array of numbers) [1,2,3] find all the combinations that can add up to the given amount/target. I understand the logic. The indexes of the array has to find all possible combinations that adds to the target, and so on. I am having trouble with this can someone guide me through. How should I go about white boarding this question? 1,1,1,1,1 1,1,1,2 1,2,2 1,1,3 2, 3
function coin(amount, array) {
var results = [], result = [], total = 0;
if (array.length === 0) {
return results;
}
if ( amount <= 0) {
return 'Enter an amount';
}
for (var i = 0; i < array.length; i++) {
return coin(amount, array.slice(1));
}
}
coin(5,[1,2,3]);