I need to understand what to do in code to return change due in coins and bills, sorted in highest to lowest order.
Otherwise, return
{status: "OPEN", change: [...]}
, with the change due in coins and bills, sorted in highest to lowest order, as the value of thechange
key.
The code so far
function checkCashRegister(price, cash, cid) {
var change = cash - price;
var response = {status: "INSUFFICIENT_FUNDS", change: []}
var cidAmt = cid.reduce( function (accumulator, current) {
return accumulator + current[1];
}, 0);
console.log(change, cidAmt)
if ( cidAmt < change ) {
response.status = "INSUFFICIENT_FUNDS";
return response;
}
else if (cidAmt === change) {
response = {status: "CLOSED", change: cid}
}
return response
}
console.log(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 (Macintosh; Intel Mac OS X 10.15; rv:97.0) Gecko/20100101 Firefox/97.0
Challenge: Cash Register
Link to the challenge: