Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions problem/implement-array-prototype-map_en.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
The function in this code takes two parameters - the callback function and `this` argument. We assign `this` to a new variable called array.
We use forEach to loop over the calling array because forEach will skip the empty elements. We call the callback function using the `.call` method
so that we can pass the this argument. We assign the output of the function to the index in the output so that the output has the corresponding
empty elements too. For example, if `this` has empty elements at index 2 and 4, the output too will have empty elements at the same indices.

There is no solution yet.
```javascript
Array.prototype.myMap = function(callbackFn, thisArg) {
const array = this;
const output = [];

Would you like to [contribute to the solution](https://github.com/BFEdev/BFE.dev-solutions/blob/main/problem/implement-array-prototype-map_en.md)? [Contribute guideline](https://github.com/BFEdev/BFE.dev-solutions#how-to-contribute)
this.forEach((element, index) => {
output[index] = callbackFn.call(thisArg, element, index, array);
});
return output;
}
```