Been trying to complete the cash register problem for a week, and am stuck on printing all the values been deducted, maybe someone can notify me where necessary…

function checkCashRegister(price, cash, cid) {
 var productPrice = price;
 var payment = cash;
 var currentCash = [...cid];
 var remain = payment - productPrice;
 var filterCashFlow = [];
 var ChangeToGive = [];

 var currency = [['PENNY',0.01],
//it will save current cash thats greater than the currency
for(let i=0; i<currency.length; i++){
for(let i=0;i<currency.length;i++){//this is where is giving me headeach
    if(currentCash.indexOf(currency[i])) ChangeToGive.push(currentCash[i])
 var TotalCash  = ChangeToGive.reduce((x,y)=>{return x+y[1]},0)
 var status = ()=>{
   return(remain > TotalCash)?"INSUFFICIENT_FUNDS":
   (remain == TotalCash)?"CLOSED": 
   (remain < TotalCash)?"OPEN":false;

/*var f = currency.reduce((x,m)=>{
  let fin = 0;
  while(ChangeToGive[m][1] >0 && remain >= m[1]){
    remain -= m[1];
    ChangeToGive[m][1] -= m[1];
    m[1] += m[1];
    fin += m[1]
return x;

var f = ()=>{
let fin = 0;
let x = []; 
if(fin ==remain){
  return x;
for(let i=0; i <filterCashFlow.length; i++){

while(ChangeToGive[i][1] >=0){
ChangeToGive[i][1] -= remain;	
remain -= filterCashFlow[i][1];
filterCashFlow[i][1] += filterCashFlow[i][1];
    fin += filterCashFlow[i][1]

    remain = Math.round(remain * 100) / 100;


return x;
   function checker(){
     let check;
     if(status() == "INSUFFICIENT_FUNDS"){
    return  check = [];
   if(status() == "CLOSED"){
   return check = currentCash;
   if(status() == "OPEN"){
 return  check = f();
return check;

  // Here is your change, ma'am.
  return ({status:status(),change:checker()}) 

console.log(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]]))

Your code is big, do you have a specific question?

look at the function f(); its suppose to iterate through filteredCashFlow, while changeToGive is >= 0, then it should add increment filteredCashFlow and minus ‘remain & ChangeToGIve’… the value is expected to output this code below =>

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]]) 

I think you may want to double check the specification.

Otherwise, return {status: "OPEN", change: [...]} , with the change due in coins and bills, sorted in highest to lowest order, as the value of the change key.

does not match what you are expecting. if going by your post it looks like what you are expecting to return is an unchanged array of the imported cid array when the status is OPEN. Is that correct?

when the status returns OPEN, the function f() is to take effect…

My problem is on the function f() its suppose to return the change from the ChangeToGive array

take not i reversed the changeToGive and filterCashFlow array…
ChangeToGive => is the cid with index of elements in filterCashFlow.
filterCashFlow => is the currency starting from the immediate element lower than the change`remain`

console.log(typeof status()); // returns undefined

you know its all in a function right

your return statement calls status(), which is supposed to return a string to store into the status property, which is then used in checker() to determine the value of change

return ({status:status(),change:checker()})

but status() is returning undefined for the input you have given it. not a string value or false. which means checker() is not going to function the way you are expecting. which results in an incorrect output.

sorry i figured it out and forgot to update you guys last month…
I just forgot to put the counter let fin=0 in the iterated environment below it, right
there in the code