No logro pasar desde el paso 12. Ayuda por favor
//Programa de gestión de inventario
const inventory = ;
function findProductIndex(productName) {
const lowerCaseProductName = productName.toLowerCase();
const index = inventory.findIndex(
(product) => product.name.toLowerCase() === lowerCaseProductName
);
return index;
}
function addProduct(product) {
product.name = product.name.toLowerCase();
// Buscar si el producto ya existe en el inventario
const existingProduct = inventory.find(item => item.name === product.name);
if (existingProduct) {
// Si existe, actualizamos la cantidad
existingProduct.quantity += product.quantity;
console.log(\`${product.name} quantity updated\`);
} else {
// Si no existe, lo agregamos al inventario
inventory.push(product);
console.log(\`${product.name} added to inventory\`);
}
}
function removeProduct(productName) {
// Normalizamos el nombre para que "FLOUR" y "flour" sean iguales
const nameToRemove = productName.toLowerCase();
// Buscamos el índice del producto
const index = inventory.findIndex(item =>
item.name.toLowerCase() === nameToRemove
);
if (index !== -1) {
// Extraemos el nombre real del producto antes de eliminarlo
const removedProduct = inventory\[index\].name;
// Remover del inventario
inventory.splice(index, 1);
console.log(\`${removedProduct} not found\`);
} else {
console.log(\`${productName} not found\`);
}
}
addProduct({name: “FLOUR”, quantity: 5})
removeProduct(“FLOUR”, 5)
console.log(inventory);
