Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a58bd77

Browse files
committed
updated oop/classes fundamental
1 parent c47fb85 commit a58bd77

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

fundamentals/oop_classes.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,29 @@ const months = [
107107

108108
const longMonths = months.filter(month => month.isLongMonth());
109109
longMonths.forEach(month => console.log(month.toString()));
110+
```
111+
112+
### Bonus: Array.prototype.map & Array.prototype.filter implementations
113+
114+
```js
115+
Array.prototype.myMap = function (mapFn) {
116+
const arr = [];
117+
for (let i = 0; i < this.length; i++) {
118+
arr.push(mapFn(this[i], i, this));
119+
}
120+
return arr;
121+
};
122+
```
123+
124+
125+
```js
126+
Array.prototype.myFilter = function (predicateFn) {
127+
const arr = [];
128+
for (let i = 0; i < this.length; i++) {
129+
if (predicateFn(this[i], i, this)) {
130+
arr.push(this[i]);
131+
}
132+
}
133+
return arr;
134+
};
110135
```

0 commit comments

Comments
 (0)