JavaScript Algorithms and Data Structures Projects - Cash Register

Hello. I never asked questions on the forum, but now it forced me, the first two checks are fine, but I can’t solve the third one, I can’t understand how to calculate correctly and the logic of the algorithm, I’ve been thinking for a long time, please help me what can be added or changed. (I don’t know English well enough to write well, so I wrote this text using google translator)

``````function checkCashRegister(price, cash, cid) {
let change;
let tmp;
let tmpArr = [];
let result = [];
let outTmp = [];
let out = cash - price;
let max = 0;
//loop
cid.map((item, index) => {
tmp = item[1];
outTmp.push(item);
result = outTmp.slice();
for (let i = 0; i < tmpArr.length; i++) {
if (tmpArr[i] > max) {
max = tmpArr[i]
}
}
})
console.log(cash);
//check
if (outTmp[0][1] === out) {
return {status: "CLOSED", change: outTmp}
}
if (price > cash) {
return {status: "INSUFFICIENT_FUNDS", change: []}
}
if (true) {
return {status: "OPEN", change: result}
}
}

let full = 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]])

console.log(full)
``````

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

Challenge: JavaScript Algorithms and Data Structures Projects - Cash Register