Tell us what’s happening:
Describe your issue in detail here.
**Your code so far**
function checkCashRegister(price, cash, cid) {
const status = {
1: "INSUFFICIENT_FUNDS",
2: "CLOSED",
3: "OPEN",
};
const denomination = {
"ONE HUNDRED": 10000,
"TWENTY": 2000,
"TEN": 1000,
"FIVE": 500,
"ONE": 100,
"QUARTER": 25,
"DIME": 10,
"NICKEL": 5,
"PENNNY": 1,
};
let change = cash * 100 - price * 100;
let amountCid = cid
.filter((f) => f[1] !== 0)
.reduce((prev, curr) => {
return prev + curr[1] * 100;
}, 0);
const sortedCid = cid
.map((obj) => [obj[0], obj[1] * 100])
.reverse()
// .sort((a, b) => {
// return a[1] === b[1] ? 0 : a[1] > b[1] ? -1 : 1;
// });
if (change > amountCid) return { status: status[1], change: [] };
else if (change === amountCid) return { status: status[2], change: cid };
else {
let sukli = []
sortedCid.forEach((elem) => {
let amount = 0;
while(change >= denomination[elem[0]] && elem[1] > 0) {
amount += denomination[elem[0]] / 100;
change -= denomination[elem[0]];
elem[1] -= denomination[elem[0]];
}
if (amount > 0)
sukli.push([elem[0], amount])
* List item
});
if (change > 0) return { status: status[1], change: [] };
else return {status: status[3], change: sukli}
}
}
const result = 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(result);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36
Challenge: Cash Register
Link to the challenge: