Hello community,
its been a while but i assure you this year contents gonna be lit π¨πΏβπ»πΊβοΈ.
So today we will be implementing the map HOF.
//map function
/**********
* @prototype _map method
* @prototype _map takes in a callback function as an argumanet
* @callbal function of _map prototype takes in the Array function
* @author: Emmanuel Onah
**********/
Array.prototype._map = function(callback){
const newArray = []
for ( let i = 0; i < this.length;i ++){
newArray.push(this[i]);
callback(this[i],i,this);
}
}
const names = ["Jerry","Joe","Jack","sashaBlanca"];
const newMappedArray = names._map((eachArrayVal,index,array)=>{
console.log(eachArrayVal,index,array)
});
newMappedArray;
Day 2: The filter array prototype
Day 3: The find array prototype
Day 4: The reduce prototype
Top comments (0)