text: const UNIT_VALUE = {
    PENNY: 0.01,
    NICKEL: 0.05,
    DIME: 0.1,
    QUARTER: 0.25,
    ONE: 1,
    FIVE: 5,
    TEN: 10,
    TWENTY: 20,
    'ONE HUNDRED': 100,
  };
  
  const checkCashRegister = (price, cash, cid) => {
    const oddMoney = cash - price;
    const reverseCid = cid.reverse();
    let remain = 0;
    let iterationMoney = oddMoney;
    const result = [];
  
    const recursionCount = (money, base, balance) => {
      const num = Math.floor(money / UNIT_VALUE[base]);
      let newMoney = money;
      if (num * UNIT_VALUE[base] >= balance) {
        newMoney = (money * 1000 - balance * 1000) / 1000;
        result.push([base, balance]);
      } else if (num * UNIT_VALUE[base] < balance && num !== 0) {
        newMoney = (money * 1000 - num * UNIT_VALUE[base] * 1000) / 1000;
        result.push([base, num * UNIT_VALUE[base]]);
        remain = (remain * 1000 + balance * 1000 - num * UNIT_VALUE[base] * 1000) / 1000;
      } else if (num === 0) {
        newMoney = money;
        remain = (remain * 1000 + balance * 1000) / 1000;
      }
      return newMoney;
    };
    // eslint-disable-next-line no-restricted-syntax
    for (const value of reverseCid) {
      iterationMoney = recursionCount(iterationMoney, value[0], value[1]);
    }
    if (iterationMoney > 0) {
      return { status: 'INSUFFICIENT_FUNDS', change: [] };
    }
    if (remain === 0 && iterationMoney === 0) {
      return { status: 'CLOSED', change: reverseCid.reverse() };
    }
    return { status: 'OPEN', change: result };
  };
  
  export default checkCashRegister;
  