JSFiddle - React, Tailwind, and code Playground
by Salmin Skenderovic
JavaScript
// 31 => 25 + 1 + 1 + 1 + 1 + 1 + 1 (false)
// 31 => 10 + 10 + 10 + 1 (true)
const coins = [25, 10, 1]
const minCoins = (num) => {
const result = getCoinResults(num);
/* console.log(counter) */
/* const most = Object.keys(counter). */
}
const getCoinResults = (num) => {
let result = 0;
for (var i=0;i<coins.length;) {
if (num <= 0) break;
const currentCoin = coins[i];
if (currentCoin <= num) {
const rest = num % currentCoin
num = num - currentCoin * coinCounter[currentCoin]
//console.log(result, num);
}
i++;
}
console.log(num)
return result;
}
minCoins(31)