first comit
This commit is contained in:
11
corrections/26-tableau-methode-reduce.js
Normal file
11
corrections/26-tableau-methode-reduce.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const panier = [
|
||||
{ nom: "Pommes", prix: 2.5 },
|
||||
{ nom: "Lait", prix: 1.2 },
|
||||
{ nom: "Pain", prix: 1.8 }
|
||||
];
|
||||
|
||||
const total = panier.reduce((accumulateur, produit) => {
|
||||
return accumulateur + produit.prix;
|
||||
}, 0); // 0 est la valeur initiale de l'accumulateur
|
||||
|
||||
console.log("Prix total du panier:", total); // Affiche 5.5
|
||||
Reference in New Issue
Block a user