-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
56 lines (41 loc) · 1.4 KB
/
index.html
File metadata and controls
56 lines (41 loc) · 1.4 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Higher Order Function</title>
</head>
<body>
<!-- Filter -->
<!-- <script>
const numbers = [-4, 9, 4, -1, -5, 8, 2, 3, -9];
// const newNumbers = numbers.filter(function (n) {
// return n >= 3;
// });
// filter with arrow function
const newNumbers = numbers.filter(n => n >= 3);
console.log(newNumbers);
</script> -->
<!-- Map -->
<!-- <script>
const numbers = [-4, 9, 4, -1, -5, 8, 2, 3, -9];
const newNumbers = numbers.map(n => n * 2);
console.log(numbers);
console.log(newNumbers);
</script> -->
<!-- Reduce -->
<!-- <script>
const numbers = [-4, 9, 4, -1, -5, 8, 2, 3, -9];
const newNumber = numbers.reduce((accumulator, currentValue) => accumulator + currentValue);
console.log(newNumber);
</script> -->
<!-- Chaining -->
<script>
const numbers = [-4, 9, 4, -1, -5, 8, 2, 3, -9];
const total = numbers.filter(n => n > 3) // will return 9, 4, 8
.map(n => n * 2) // will return 18, 8, 16
.reduce((accum, current) => accum + current); // will return 42
console.log(total);
</script>
</body>
</html>