This commit is contained in:
2025-08-28 14:34:18 +02:00
commit 5ff4c53a10
29 changed files with 1705 additions and 0 deletions

25
TP1/EX3/array.html Normal file
View File

@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Array Operations</title>
</head>
<body>
<script>
const numbers = [1, 5, 2, 8, 3, 7, 4, 6];
// Utilisation de map pour créer un nouveau tableau avec chaque nombre doublé
const doubledNumbers = numbers.map(num => num * 2);
console.log("Doubled numbers:", doubledNumbers); // [2, 10, 4, 16, 6, 14, 8, 12]
// Utilisation de filter pour garder seulement les nombres pairs
const evenNumbers = numbers.filter(num => num % 2 === 0);
console.log("Even numbers:", evenNumbers); // [2, 8, 4, 6]
// Utilisation de reduce pour calculer la somme de tous les nombres
const sum = numbers.reduce((total, num) => total + num, 0);
console.log("Sum:", sum); // 36
</script>
</body>
</html>

31
TP1/EX3/minmax.html Normal file
View File

@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>Min/Max with Reduce</title>
</head>
<body>
<script>
function minmax(array) {
if (array.length === 0) {
return { min: undefined, max: undefined };
}
return array.reduce(
(acc, val) => {
return {
min: Math.min(acc.min, val),
max: Math.max(acc.max, val)
};
},
{ min: array[0], max: array[0] }
);
}
const data = [10, 5, 20, 3, 15];
const result = minmax(data);
console.log("Min/Max:", result); // { min: 3, max: 20 }
</script>
</body>
</html>