let inventory=[];
function findProductIndex(pname){
pname=pname.toLowerCase();
let c=0;
for(let i=0;i<inventory.length;i++){
if(inventory\[i\].name==pname){
c=1;
return i;
}
}
if(c==0){
return -1;
}
}
function addProduct(obj){
obj.name=obj.name.toLowerCase();
let c=0;
for(let i=0;i<inventory.length;i++){
if(inventory\[i\].name== obj.name){
inventory\[i\].quantity=inventory\[i\].quantity + obj.quantity;
console.log(\`${inventory\[i\].name} quantity updated\`);
c=1;
}
}
if(c==0){
inventory.push(obj);
console.log(obj.name + " added to inventory" );
}
}
function removeProduct(name,qua){
name=name.toLowerCase();
let c=0;
for(let i=0;i<inventory.length;i++){
if(inventory\[i\].name== name){
c=1;
if(inventory\[i\].quantity<qua){
console.log(\`Not enough ${inventory\[i\].name} available, remaining pieces: ${inventory\[i\].quantity}\`);
}
else if(inventory\[i\].quantity==qua){
inventory.splice(i,1);
}
else{
inventory\[i\].quantity=inventory\[i\].quantity - qua;
console.log(\`Remaining ${inventory\[i\].name} pieces: ${inventory\[i\].quantity}\`)
}
}
}
if(c==0){
console.log(\`${name} not found\`);
}
}
removeProduct(“FLOUR”, 1)
addProduct({name: “FLOUR”, quantity: 5});
addProduct({name: “FLOUR”, quantity: 5})
removeProduct(“FLOUR”, 5)
removeProduct(“FLOUR”, 5)