JSFiddle - React, Tailwind, and code Playground
by akhildev
JavaScript
let a =[1, 2, -3, -4];
let count = 10;
var tempCount = 10;
for(let i =0; i<a.length;i++){
if(a[i]>0 && a[i]<=tempCount){
tempCount -= a[i];
console.log(`Request for ${a[i]} tickets approved; remaining ${tempCount} `);
}else if(a[i]>0 && a[i]>tempCount){
console.log(`Request for ${a[i]} tickets denied; remaining ${tempCount}`)
}else if(a[i]<0 && ((tempCount-a[i]) <= 10)){
var val = a[i]* -1;
tempCount +=val;
console.log(`Request for canceling ${val} tickets approved; remaining ${tempCount}
`);
}else if(a[i]<0 && ((tempCount-a[i]) > 10)){
var sold = count-tempCount;
var val = a[i]* -1;
console.log(`Request for canceling ${val} tickets denied; sold ${sold}; remaining ${tempCount}
`);
}
}