DEV Community

loading...
Cover image for DAY 1 of building the Higher Order Functions in javascript. the map Higher Order Function.

DAY 1 of building the Higher Order Functions in javascript. the map Higher Order Function.

Emmanuel Onah
Frontend Architect
Updated on ・1 min read

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;
Enter fullscreen mode Exit fullscreen mode

Alt Text

Day 2: The filter array prototype
Day 3: The find array prototype
Day 4: The reduce prototype

Discussion (0)