# My crazy Cash register program finally Done!

``````let myarry=[0.01,0.05,0.1,0.25,1,5,10,20,100]
let mydrwawer={0.01:"PENNY",0.05:"NICKEL",0.1:"DIME",0.25:"QUARTER",1:"ONE",5:"FIVE",10:"TEN",20:"TWENTY",100:"ONE HUNDRED"}

function getallmoney(arr){
let money=[]
for(let i=0;i<arr.length;i++){
money.push(arr[i][1]/arr[i][0])
}
return money;
}

function getsumsinDrawer(arr){
let sums=[];
for(let i=0;i<arr.length;i++){
sums.push(arr[i][1])
}
//console.log(sums)
return sums.reduce((x,y)=>x+y);
}
function getChangeInDue(change,array){
let need=[];
for(let i=0;i<array.length;i++){
if(change>=array[i][1])
{
need.push(array[i][1]);
change=change-array[i][1]
}
else if(change<array[i][1]){
need.push(change-change%array[i][0])
change=change%array[i][0]
}
}
need[need.length-1]=parseFloat(parseFloat(change+need[need.length-1]).toFixed(2));
for(let i=0;i<array.length;i++){
array[i][1]=need[i];
array[i][0]=mydrwawer[array[i][0]]
}

return array.filter(x=>x[1]>0);
}

function getrepresentationToNumericNamin(arr){
for(let i=0;i<arr.length;i++){
switch(arr[i][0]){
case "PENNY":
//arr[i][1]=arr[i][1]/0.01
arr[i][0]=0.01;
break;
case "NICKEL":
//arr[i][1]=Math.round(arr[i][1]/0.05)
arr[i][0]=0.05;
break;
case "DIME":
//arr[i][1]=arr[i][1]/0.1
arr[i][0]=0.1;
break;
case "QUARTER":
// arr[i][1]=arr[i][1]/0.25
arr[i][0]=0.25;
break;
case "ONE":
//arr[i][1]=arr[i][1]/1
arr[i][0]=1;
break;
case "FIVE":
//arr[i][1]=arr[i][1]/5
arr[i][0]=5;
break;
case "TEN":
// arr[i][1]=arr[i][1]/10
arr[i][0]=10;
break;
case "TWENTY":

//
//arr[i][1]=arr[i][1]/20
arr[i][0]=20;
break;
case "ONE HUNDRED":
//arr[i][1]=arr[i][1]/100
arr[i][0]=100;
break;
}

}
return arr;
}
function getrepresentativeToStringNameing(arr){
for(let i=0;i<arr.length;i++){
switch(arr[i][0]){
case  0.01:
//arr[i][1]=arr[i][1]/0.01
arr[i][0]="PENNY";
break;
case 0.05:
//arr[i][1]=Math.round(arr[i][1]/0.05)
arr[i][0]="NICKEL";
break;
case 0.1:
//arr[i][1]=arr[i][1]/0.1
arr[i][0]="DIME";
break;
case 0.25:
// arr[i][1]=arr[i][1]/0.25
arr[i][0]="QUARTER";
break;
case 1 :
//arr[i][1]=arr[i][1]/1
arr[i][0]="ONE";
break;
case 5:
//arr[i][1]=arr[i][1]/5
arr[i][0]="FIVE";
break;
case 10:
// arr[i][1]=arr[i][1]/10
arr[i][0]="TEN";
break;
case 20:

//
//arr[i][1]=arr[i][1]/20
arr[i][0]="TWENTY";
break;
case 100 :
//arr[i][1]=arr[i][1]/100
arr[i][0]="ONE HUNDRED";
break;
}

}
return arr

}
function getChangesforArry(num,arr){
return arr.filter(x=>x<num)[arr.filter(x=>x<num).length-1]
}
function getNeedChanges(changeInDue,arr){
return  getrepresentationToNumericNamin(arr).filter(x=>x[0]<changeInDue)[arr.filter(x=>x[0]<changeInDue).length-1][1];

}
function checkCashRegister(price, cash, cid) {
let a=getsumsinDrawer(cid);

let chages=cash-price;

let maxChangeForUse=getChangesforArry(cash-price,myarry);

``````

some code missing