Array.prototype.myMap = function(fn) {
const res = [];
if (!Array.isArray(this)) {
return 'this is not array';
}
for (i = 0; i < this.length; i++ ) {
res.push(fn(this[i], i, this));
}
return res;
}
const res1 = [1,2,3,4].myMap((item) => {
return item + 1;
});
console.log(res1);