Cash Register: Help with Logic

Tell us what’s happening:
I have been stuck for a while now trying to solve this. I am having difficulties doing a deduction especially when I shift to a lower denomination that has more value than my reducing change. Please I need help on how I can improve the logic.

Your code so far


function checkCashRegister(price, cash, cid) {
 let change = cash-price;
 let response = {};
 //array for pushing computed change values
 let amount = [];
  //change or denomination values
  let changeValues = [["PENNY", 0.01],["NICKEL",0.05],["DIME",0.1],["QUARTER",0.25],["ONE",1],["FIVE",5],["TEN",10],["TWENTY",20],["ONE HUNDRED",100]];

  //total cash in drawer
  let totalCid = cid.map(x => x[1]).reduce((x,y) => y + x).toFixed(2);

  if (totalCid < change){
    response['status'] = "INSUFFICIENT_FUNDS";
    response['change'] = amount;
  }
  else if(totalCid == change){
    response['status'] = "CLOSED";
    response['change'] = cid;

  }
  else {
    //get the change or denom values that are relevent for issuing change
    let smallDrawer = changeValues.filter(x => x[1]< change);
    
    //callback to filter actual relevant values from cid
    function getChange(x){
      return cid.filter(y => y.indexOf(x[0]) > -1);
    }
    
    //filtered cid values
    smallDrawer = [].concat(smallDrawer.map(x => getChange(x))).flat();

    //total filtered cid values
    let totalsmallDrawer = smallDrawer.map(x => x[1]).reduce((x,y) => y + x).toFixed(2);

    //check for when condition is : cannot return exact change
    if(totalsmallDrawer < change){
      response['status'] = "INSUFFICIENT_FUNDS";
      response['change'] = amount;
    }
    /* This is where I am stuck, help with logic please esp when modulo does not work where small drawer value is of small denom with high value e.g "FIVE",55 */
    else {
        let i = smallDrawer.length - 1;
        while(i >= 0){
          if(change / smallDrawer[i][1] < 1){
            let value = [smallDrawer[i][0], change];
            amount.push(value);
            response['status'] = "OPEN";
            response['change'] = amount;
            change = 0;
            break;
          }
          else{
            let value = smallDrawer[i];
            change = Number.parseFloat((change % smallDrawer[i][1]).toFixed(2));
            amount.push(value);
            i -= 1;
            }
         //i -= 1;
        }
      }
    }
    console.log(amount);
    return response;
  }

  //console.log(response);
 // return response;

// 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(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]]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/cash-register/