JavaScript Algorithms and Data Structures Projects - Cash Register

Tell us what’s happening:

This code works perfectly fine until pennies get involved within the function, for the given test case here, the pennies in change is showing 0.03 instead of 0.04 to satisfy the change of 96.74 dollars. Can anyone tell me why is this happening

Your code so far

function checkCashRegister(price, cash, cid) {
  const currency = {"ONE HUNDRED":100, "TWENTY":20, "TEN":10, "FIVE":5, "ONE":1, "QUARTER":0.25, "DIME":0.1, "NICKEL":0.05, "PENNY":0.01};
  let changeAmount = cash-price;
  let registerTotal = cid.reduce((sum,cur) => sum+=cur[1],0);
  let registerStatus = {status: "CLOSED", change:cid}

  if(registerTotal<changeAmount) {
    registerStatus.status = "INSUFFICIENT_FUNDS";
    registerStatus.change = [];
  }
  
  else if(registerTotal>changeAmount) {
    let changeArr = cid
      .reverse()
      .reduce((change,cur) => {
        let pushValue=0;
        while(changeAmount>=currency[cur[0]]&&cur[1]!=0) {
          changeAmount -= currency[cur[0]];
          cur[1] -= currency[cur[0]];
          pushValue += currency[cur[0]];
        }
        if(pushValue!=0) {
          change.push([cur[0],pushValue])
        }
        return change
      } ,[])
    registerStatus.status = "OPEN";
    registerStatus.change = changeArr;
  }
  console.log(registerTotal);
  return registerStatus;
}

console.log(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]]));

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14092.77.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.107 Safari/537.36

Challenge Information:

JavaScript Algorithms and Data Structures Projects - Cash Register