DEV Community

Discussion on: Implementing our own Array.map() method in javascript

Collapse
 
kyselberg profile image
Illia Kyselov • Edited

here is i've wrote with context passing

Array.prototype.myMap = function(cb, thisArg) {
const newArray = [];
const that = thisArg || this;
const thatLength = that.length;

for (let i = 0; i < thatLength; i++) {
    const el = cb.call(that, that[i], i, that);
    newArray.push(el);
}

return newArray;
Enter fullscreen mode Exit fullscreen mode

};