编辑代码

//JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
function change(money, coins) {
  const n = coins.length;
  let count = 0;
  coins.sort((a, b) => b - a);
  for (let i = 0; i < n; i++) {
    while (money >= coins[i]) {
      money -= coins[i];
      count++;
    }
  }
  return count;
}

const money = 63;
const coins = [1, 5, 10, 20, 50];
console.log(change(money, coins)); // 6