📜  function change(cash) { 你的代码在这里 return { 二:0,五:0,十:0 }; } - Go 编程语言代码示例

📅  最后修改于: 2022-03-11 14:44:59.212000             🧑  作者: Mango

代码示例1
function giveChange(amount) {
    var ch = { two:0, five:0, ten:0 };

    if ( amount < 2 || amount == 3 ) return;

    if ( amount % 2 ) {
        amount -= 5;
        ch.five = 1;
    }   
    
    while ( amount % 10 ) {
        amount -= 2;
        ch.two ++;
    }

    ch.ten = amount/10;

    return ch;
}

console.log(giveChange(12));
console.log(giveChange(27));
console.log(giveChange(33));