66 </a >
77</p >
88
9- Sure, here's the complete text converted into Markdown:
10-
11- ## Map in JavaScript
9+ ### Map in JavaScript
1210
1311``` javascript
1412const employees = [
@@ -18,8 +16,12 @@ const employees = [
1816];
1917
2018const employeesName = employees .map (employee => employee .name );
19+ console .log (myEmployeesName); // ["John", "Sarah", "Michael"]
20+ ```
21+
22+ ### Polyfill of map()
2123
22- // Polyfill of map()
24+ ``` javascript
2325if (! Array .prototype .myMap ) {
2426 Array .prototype .myMap = function (callback ) {
2527 const result = [];
@@ -35,7 +37,7 @@ const myEmployeesName = employees.myMap(employee => employee.name);
3537console .log (myEmployeesName); // ["John", "Sarah", "Michael"]
3638```
3739
38- ## Filter In JavaScript
40+ ### Filter In JavaScript
3941
4042``` javascript
4143const products = [
@@ -45,8 +47,15 @@ const products = [
4547];
4648
4749const availableProducts = products .filter (product => product .inStock );
50+ // [
51+ // { name: 'iPhone', price: 999, inStock: true },
52+ // { name: 'Google Pixel', price: 799, inStock: true },
53+ // ]
54+ ```
4855
49- // Polyfill of filter()
56+ ### Polyfill of filter()
57+
58+ ``` javascript
5059if (! Array .prototype .myFilter ) {
5160 Array .prototype .myFilter = (callback ) => {
5261 const result = [];
@@ -68,7 +77,7 @@ console.log(availableProducts);
6877// ]
6978```
7079
71- ## Reduce in JavaScript
80+ ### Reduce in JavaScript
7281
7382``` javascript
7483const orders = [
@@ -81,7 +90,12 @@ const totalAmount = orders.reduce(function (accumulator, order) {
8190 return accumulator + order .price * order .quantity ;
8291}, 0 );
8392
84- // Polyfill of reduce()
93+ console .log (totalAmount); // 5294
94+ ```
95+
96+ ### Polyfill of reduce()
97+
98+ ``` javascript
8599if (! Array .prototype .myFilter ) {
86100 Array .prototype .myReduce = (callback , initialValue ) => {
87101 let accumulator = initialValue === undefined ? this [0 ] : initialValue;
@@ -96,7 +110,7 @@ const myTotalAmount = orders.myReduce(function (accumulator, order) {
96110 return accumulator + order .price * order .quantity ;
97111}, 0 );
98112
99- console .log (totalAmount);
113+ console .log (totalAmount); // 5294
100114```
101115
102116### Question 1: Find the longest word length
0 commit comments