09-Javascript Higher Order Functions (map(), reduce(), filter())


Hey guys, welcome back to DevPremier In this video, we will cover Javascript Higher Order Functions These are the functions, that we are gonna cover, map(), reduce(), and filter() This is the basic definition of the map method The map method calls the provided function once for each element in the array and returns a new array with the results of calling the function for every array element so, let’s have an example here, we have an array “numbers” numbers.map here, we will call a function it will return element into 2 so, here we have each element multiplied by 2 in the result we can also use ES6 standard here or you can say ECMAScript2015 So, this is the way to use ES6 using arrow function, you have to write here “element” and then function definition element * 2 see this, we have the same result using ES6, And this very short method you can also make reusable function and pass the in the map method, let’s try with this and this will return here pass the square function so, this is how it works. this method is very important, if you learning nodejs or reactjs or any javascript framework we are gonna use map method very widely when you want to print any list or you want to loop any function over a list then function will be very useful the very useful definition of thr map method is to print print the list of array items let me show you with an example here here we have a list of items make a const “person” so, this way we can use the map method to print the list so, this is the very important application of map method The next method is the “reduce()” method This is the basic definition of the reduce method the reduce method reduces the array to a single value the reduce method method executes a provided function fo eah value of the array Let’s create an array of numbers so, here we have 4 elements in the array the first element is 170 and then 30, 10 and 20 what we are doing here is first it will take 170 and then and then it will 30 in the 170 and then it will 10 in the 170 and then it will 20 in the 170 170 + 30=200, 200 +10, 210 + 20 210 + 20=230

Add a Comment

Your email address will not be published. Required fields are marked *