I have been able to get this far though:
function checkCashRegister(price, cash, cid) {
var cidtotal = 0;
var cid2 = [];
var temp = [];
var real2 = [];
/* var real = [["PENNY", 0.01], ["NICKEL", 0.05], ["DIME", 0.1], ["QUARTER", 0.25], ["ONE", 1], ["FIVE", 5], ["TEN", 10], ["TWENTY", 20], ["ONE HUNDRED", 100]];
*/
var real = [0.01, 0.05, 0.1, 0.25, 1, 5, 10, 20, 100];
var change = cash - price;
console.log(change);
for (x = 0; x < cid.length; x++) {
cid2.push(cid[x][1]);
}
console.log(cid2);
cidtotal = cid2.reduce(function(item, total) {
return item + total;
}, 0);
console.log(cidtotal);
var real2 = real.slice();
console.log(real2);
if (change > cidtotal) {
return {"status" : "INSUFFICIENT_FUNDS", "change" : []};
}
else if (change == cidtotal) {
return {"status" : "CLOSED", "change" : cid};
}
else if (change < cidtotal) {
for (var i = real.length-1; i >= 0; i--) {
while (real[i] < (cid2[i] - real2[i])) {
real[i] = real[i] + real2[i];
}
temp.push(real[i]);
}
console.log(temp);
}
}
// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.1],
// ["QUARTER", 4.25],
// ["ONE", 90],
// ["FIVE", 55],
// ["TEN", 20],
// ["TWENTY", 60],
// ["ONE HUNDRED", 100]]
checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);