6
6
</a >
7
7
</p >
8
8
9
- Sure, here's the complete text converted into Markdown:
10
-
11
- ## Map in JavaScript
9
+ ### Map in JavaScript
12
10
13
11
``` javascript
14
12
const employees = [
@@ -18,8 +16,12 @@ const employees = [
18
16
];
19
17
20
18
const employeesName = employees .map (employee => employee .name );
19
+ console .log (myEmployeesName); // ["John", "Sarah", "Michael"]
20
+ ```
21
+
22
+ ### Polyfill of map()
21
23
22
- // Polyfill of map()
24
+ ``` javascript
23
25
if (! Array .prototype .myMap ) {
24
26
Array .prototype .myMap = function (callback ) {
25
27
const result = [];
@@ -35,7 +37,7 @@ const myEmployeesName = employees.myMap(employee => employee.name);
35
37
console .log (myEmployeesName); // ["John", "Sarah", "Michael"]
36
38
```
37
39
38
- ## Filter In JavaScript
40
+ ### Filter In JavaScript
39
41
40
42
``` javascript
41
43
const products = [
@@ -45,8 +47,15 @@ const products = [
45
47
];
46
48
47
49
const availableProducts = products .filter (product => product .inStock );
50
+ // [
51
+ // { name: 'iPhone', price: 999, inStock: true },
52
+ // { name: 'Google Pixel', price: 799, inStock: true },
53
+ // ]
54
+ ```
48
55
49
- // Polyfill of filter()
56
+ ### Polyfill of filter()
57
+
58
+ ``` javascript
50
59
if (! Array .prototype .myFilter ) {
51
60
Array .prototype .myFilter = (callback ) => {
52
61
const result = [];
@@ -68,7 +77,7 @@ console.log(availableProducts);
68
77
// ]
69
78
```
70
79
71
- ## Reduce in JavaScript
80
+ ### Reduce in JavaScript
72
81
73
82
``` javascript
74
83
const orders = [
@@ -81,7 +90,12 @@ const totalAmount = orders.reduce(function (accumulator, order) {
81
90
return accumulator + order .price * order .quantity ;
82
91
}, 0 );
83
92
84
- // Polyfill of reduce()
93
+ console .log (totalAmount); // 5294
94
+ ```
95
+
96
+ ### Polyfill of reduce()
97
+
98
+ ``` javascript
85
99
if (! Array .prototype .myFilter ) {
86
100
Array .prototype .myReduce = (callback , initialValue ) => {
87
101
let accumulator = initialValue === undefined ? this [0 ] : initialValue;
@@ -96,7 +110,7 @@ const myTotalAmount = orders.myReduce(function (accumulator, order) {
96
110
return accumulator + order .price * order .quantity ;
97
111
}, 0 );
98
112
99
- console .log (totalAmount);
113
+ console .log (totalAmount); // 5294
100
114
```
101
115
102
116
### Question 1: Find the longest word length
0 commit comments