Can someone help me out with this? I can’t quite figure out why it’s not passing. Normally I’d go through the motions until I figure it out but I’ve been staring at this thing for quite a while. Code in Summary drop-down.
Summary
var money = [
{name:“ONE HUNDRED”, value: 100.00},
{name:“TWENTY”, value: 20.00},
{name:“TEN”, value: 10.00},
{name:“FIVE”, value: 5.00},
{name:“ONE”, value: 1.00},
{name:“QUARTER”, value: 0.25},
{name:“DIME”, value: 0.10},
{name:“NICKEL”, value: 0.05},
{name:“PENNY”, value: 0.01},
];
function checkCashRegister(price, cash, cid) {
var change = cash - price;
var till = cid.reduce(function(a,b){
return a + b[1];
}, 0.0).toFixed(2);
if (till < change) {
return “INSUFFICIENT_FUNDS”;
} else if (till === change){
return “CLOSED”;
};
cid = cid.reverse();
var result = money.reduce(function(acc, next, index){
if(change >= next.value){
var currentValue = 0.0;
while(change >= next.value && cid[index][1] >= next.value){
currentValue += next.value;
change -= next.value;
change = Math.round(change*100)/100;
cid[index][1] -= next.value;
}
acc.push([next.name, currentValue]);
return acc;
} else {
return acc;
}
}, []);
return result.length > 0 && change === 0 ? result : “INSUFFICIENT_FUNDS”;
}
checkCashRegister(19.5, 20, [[“PENNY”, 1.01], [“NICKEL”, 2.05], [“DIME”, 3.1], [“QUARTER”, 4.25], [“ONE”, 90], [“FIVE”, 55], [“TEN”, 20], [“TWENTY”, 60], [“ONE HUNDRED”, 100]]);