Skip to content

Commit 52bbab6

Browse files
committed
added polyfill and timecomplexity in curriculum
1 parent 8e8caa2 commit 52bbab6

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

Array/Polyfill.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
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
1412
const employees = [
@@ -18,8 +16,12 @@ const employees = [
1816
];
1917

2018
const 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
2325
if (!Array.prototype.myMap) {
2426
Array.prototype.myMap = function (callback) {
2527
const result = [];
@@ -35,7 +37,7 @@ const myEmployeesName = employees.myMap(employee => employee.name);
3537
console.log(myEmployeesName); // ["John", "Sarah", "Michael"]
3638
```
3739

38-
## Filter In JavaScript
40+
### Filter In JavaScript
3941

4042
```javascript
4143
const products = [
@@ -45,8 +47,15 @@ const products = [
4547
];
4648

4749
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+
```
4855

49-
// Polyfill of filter()
56+
### Polyfill of filter()
57+
58+
```javascript
5059
if (!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
7483
const 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
8599
if (!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

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@
2323
## Curriculum
2424

2525
- [Loops in JavaScript](https://github.com/Vishal-raj-1/DSA-In-JS-With-Vishal/blob/main/Basics/README.md)
26-
- [Array](https://github.com/Vishal-raj-1/DSA-In-JS-With-Vishal/blob/main/Array/README.md)
26+
- [Time Complexity: Big O notation](https://github.com/Vishal-raj-1/DSA-In-JS-With-Vishal/blob/main/Time%20Complexity/README.md)
27+
- [Array](https://github.com/Vishal-raj-1/DSA-In-JS-With-Vishal/blob/main/Array/README.md)
28+
- [Polyfill of Map, Filter & Reduce](https://github.com/Vishal-raj-1/DSA-In-JS-With-Vishal/blob/main/Array/Polyfill.md)

0 commit comments

Comments
 (0)