From the course: Learning Functional Programming with JavaScript ES6+

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Challenge: Recreate the map function

Challenge: Recreate the map function - JavaScript Tutorial

From the course: Learning Functional Programming with JavaScript ES6+

Start my 1-month free trial

Challenge: Recreate the map function

(upbeat music) - [Instructor] Now that we've had a lot of practice with JavaScript's functional parts such as built in array functions, let's do a challenge. The challenge here, to make sure you really understand how the map function works, is to recreate the map function. Specifically, what we want to create is a function called map that takes two arguments. The first argument is an array and the second argument is a function that should be applied to every element in the array. Your task is to recreate the map function in this way, obviously without using JavaScript's built in map function. There are quite a few different solutions to this problem but one of the easier solutions is to use a for Loop and one of the harder versions is to use only JavaScript's built in reduce function. You'll want to write your code inside the body of this map function here and if you've implemented it correctly, when you run your code, these lines here should print the correct answers to the console…

Contents