let stock = [ id: 1, nom: "Stylo", prix: 1.5, quantite: 50 }, { id: 2, nom: "Cahier", prix: 3.0, quantite: 30 } ]; // 1. Rechercher un produit function rechercherProduit(nomRecherche) { const resultat = stock.filter(p => p.nom.toLowerCase().includes(nomRecherche.toLowerCase())); return resultat.length > 0 ? resultat : "Aucun produit trouvé."; } // 2. Modifier un produit function modifierProduit(id, nouveauPrix, nouvelleQuantite) { const produit = stock.find(p => p.id === id); if (produit) { produit.prix = nouveauPrix !== undefined ? nouveauPrix : produit.prix; produit.quantite = nouvelleQuantite !== undefined ? nouvelleQuantite : produit.quantite; return "Produit mis à jour avec succès."; } return "Produit introuvable."; } // 3. Supprimer un produit function supprimerProduit(id) { const index = stock.findIndex(p => p.id === id); if (index !== -1) { stock.splice(index, 1); return "Produit supprimé du stock."; } return "Produit introuvable."; }
Hosted & Compiled with HtmlRunner.com