Money dispenser

This program gives you the minimum number of coins required to dispense an amount. Returns Insufficient Funds if the anount is more than what ia available in the bank.

by Saksham Malhotra

JavaScript

let c = {
            do: { c: 31, v: 100 },
            p: { c: 23, v: 25 },
            d: { c: 5, v: 10 },
            n: { c: 1, v: 5 },
            c: { c: 43, v: 1 }
        };
        let cd = {
            do: 0,
            p: 0,
            d: 0,
            n: 0,
            c: 0
        }

        let w = function (a) {
            a = a * 100;
            let cb = JSON.parse(JSON.stringify(c));
            let tot = 0;
            for (val in cb) {
                cd[val] = parseInt(a / c[val].v);
                cb[val].c = cb[val].c > cd[val] ? (cb[val].c - cd[val]) : 0;
                tot += c[val].v * cd[val];
                a = a - c[val].v * cd[val];
                if (a == 0)
                    break;
            }
            if (a == 0) {
                console.log(cd);
                console.log(cb);
            }
            else {
                console.log('IF');
            }
        }
        w(12.59);