Skip to content

Instantly share code, notes, and snippets.

@tamunoibi
Created November 21, 2018 20:42
Show Gist options
  • Select an option

  • Save tamunoibi/c683ccac81ce429bcab2fa6dba8a4238 to your computer and use it in GitHub Desktop.

Select an option

Save tamunoibi/c683ccac81ce429bcab2fa6dba8a4238 to your computer and use it in GitHub Desktop.
function countChange (money,coins) {
const arr = [];
let sum;
for(let i = 0; i < coins.length; i++) {
for(let j = 0; j < coins.length; j++) {
let value = coins[i] + coins[j];
//console.log(value, value, value);
if(value === money) {
arr.push(value);
}
//console.log(coins[i], coins[j]);
}
}
coins.forEach(e => {
sum = e;
while (sum < money) {
sum += e;
if(sum === money) {
arr.push(sum);
}
}
});
let bigHead = coins.reduce(function (accumulator, currentValue) {
return accumulator + currentValue;
}, 0);
if (bigHead === money) {
arr.push(bigHead);
}
return arr.length;
}
countChange(10, [5, 2, 3]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment