-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloops.js
66 lines (52 loc) · 1.23 KB
/
loops.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const people = [
{ name: "Bienfait", age: 24, gender: "m" },
{ name: "Gloire", age: 34, gender: "m" },
{ name: "Josue", age: 4, gender: "m" },
{ name: "Yasmine", age: 25, gender: "f" },
{ name: "Glody", age: 50, gender: "f" },
{ name: "Divine", age: 15, gender: "f" },
];
const fil = (e) => e.age < 17 || e.gender === 'f'
// filter
const res = people.filter(fil);
console.log(res);
console.log("\n++++++++++++++++++++++++");
const numbers = [90, 80, 454, 53];
console.log("filter");
const n_filtered = numbers.filter((e) => e % 2 === 0);
console.log(n_filtered);
// map
console.log("map");
const numbers_2 = numbers.map((e, i) => e);
console.log(numbers_2);
// foreach
console.log("foreach");
numbers.forEach((e, i) => {
console.log(`${e}:${i}`);
if (i === 2) {
numbers[i] = "Good";
}
});
console.log(numbers)
console.log("\n+++++++++++++++++");
// parcours avec for loop
for (let i = 0; i < numbers.length; i++) {
console.log(numbers[i]);
}
console.log("\n+++++++++++++++++");
let count = 0;
// while
while (count < 9) {
console.log(count);
count = count + 1;
}
// do while
do {
console.log(count);
count++;
} while (count < 9);
// for loop
console.log(`for loop`);
for (let i = 0; i < 9; i++) {
console.log(i);
}