Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Writing two functions as the following instruction map & filter by using JavaScript . Input [2,7,6,9,1,4] *Exercise 2 Higher Order Functions * Let's get some
Writing two functions as the following instruction map & filter by using JavaScript.
Input [2,7,6,9,1,4]
*Exercise 2 Higher Order Functions * Let's get some practice with JavaScript functions by implementing some variants * of the higher-order functions * Note: JavaScript (since its fifth edition) has built-in map, filter, and reduce functions * This is great because it means you can use them in the other exercises and your subsequent homeworks ! However, I have disabled them for this exercise, so you do have to write the functions yourself * First, let's implement map. Map takes in * two arguments-an array to perform the mapping on, and the mapping function. * It applies the mapping function to all elements in the array and returns an array of results var map-function (array, mappingFunction) /1 Your code goes here *Next, let's implement filter. Filter takes in * two arguments - an array to filter, and a filtering function. It returns a list of all * elements of the array such that filterFunction (element) ue. var filter-function (array, filterFunction) /1 Your code goes here *Exercise 2 Higher Order Functions * Let's get some practice with JavaScript functions by implementing some variants * of the higher-order functions * Note: JavaScript (since its fifth edition) has built-in map, filter, and reduce functions * This is great because it means you can use them in the other exercises and your subsequent homeworks ! However, I have disabled them for this exercise, so you do have to write the functions yourself * First, let's implement map. Map takes in * two arguments-an array to perform the mapping on, and the mapping function. * It applies the mapping function to all elements in the array and returns an array of results var map-function (array, mappingFunction) /1 Your code goes here *Next, let's implement filter. Filter takes in * two arguments - an array to filter, and a filtering function. It returns a list of all * elements of the array such that filterFunction (element) ue. var filter-function (array, filterFunction) /1 Your code goes hereStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started