Pages

Special event

Function Style, Method Style

 The main difference between the function style and the use of the `filter() or map()` method lies 

in the programming paradigm they represent.


🥇**Function Style**: The function style represents the procedural programming paradigm.

🎖️ **Method Style**: The method style represents the functional programming paradigm.

Création de sa propre librairie de fonctions !

 loops to methods

Mon forEach

const corbeille = ["Orange", "Banane", "Ananas", "Pamplemousse"];

1) Afficher les fruits de la corbeille de fruits.



2) Coupez les fruits en deux.

 

3) Comment utiliser cette fonction

function randomDrink(fruit, i, fruits) {
  const drinks = ["🥤", "🧋", "🍹"];
  const choice = drinks[Math.floor(Math.random() * drinks.length)];
  const article = /^[aeiou]/i.test(fruit) ? "d'" : "de ";
  fruits[i] = `${choice} ${article}${fruit}`;
}

TD : foreach


 🔢 1.1 Doubling Each Number
onst numbers = [3, 7, 10, 2];
console.log(numbers); // [6, 14, 20, 4] 
🔢 1.2 Tripling Each Number
onst numbers = [3, 7, 10, 2];
console.log(numbers); // [9, 21, 30, 12]
🔢 1.3 Doubling Each Number (new array)
onst numbers = [3, 7, 10, 2];
console.log(doubled); // [6, 14, 20, 4]
---

📉 2. Finding the Maximum Value

const numbers = [15, 42, 8, 33];
console.log(`Max: ${max}`); // Max: 42

---

🧮 3. Counting Even Numbers
const numbers = [4, 9, 12, 7, 6];
console.log(`Even numbers: ${count}`); // Even numbers: 3

---

📊 4. Creating a Frequency Map
const numbers = [1, 2, 2, 3, 3, 3];
const frequency = {};
console.log(frequency); // { '1': 1, '2': 2, '3': 3 }

---

🧹 5. Cleaning or Normalizing Dat
const rawData = [102, 98, 105, 100]; console.log(normalized); // [2, -2, 5, 0]

---

📦 6. Transforming API Dat
const users = [
  { name: "Alice", age: 30 },
  { name: "Bob", age: 25 },
  { name: "Charlie", age: 35 }
];
console.log(names); // ["Alice", "Bob", "Charlie"]