Skip to content

Commit 48a92a7

Browse files
authored
Merge pull request #15 from abhisheksatre/master
Implemented Array.map method #hacktoberfest
2 parents b5a58b4 + c5b7a22 commit 48a92a7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

implementations/map.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
*
3+
The map() method creates a new array with the results of calling a provided function on every element in the calling array
4+
5+
Callback is invoked with three arguments:
6+
- the value of the element
7+
- the index of the element
8+
- the Array object being traversed
9+
*/
10+
11+
Array.prototype.myMap = function(callback, thisArg) {
12+
var mapArray = [];
13+
for (let i = 0; i < this.length; i++) {
14+
mapArray.push(callback.call(thisArg, this[i], i, this));
15+
}
16+
return mapArray;
17+
};
18+

0 commit comments

Comments
 (0)