Question
I need help understanding the following. How would you go about it? I tried it a million different ways, and I cant get to it.
I need help understanding the following. How would you go about it? I tried it a million different ways, and I cant get to it. I having trouble creating a function inside a function with two other functions? My main function becomes undefined anytime I try to add multiple functions. Also, where does currentArray come into play?
Problem below:
Declare a global function named cs142MakeMultiFilter that takes an array (originalArray) as a parameter and returns a function that can be used to filter the elements of this array. The returned function (arrayFilterer) internally keeps track of a notion called currentArray. Initially, currentArray is set to be identical to originalArray. The arrayFilterer function takes two functions as parameters. They are:
- filterCriteria - A function that takes an array element as a parameter and returns a boolean. This function is called on every element of currentArray and currentArray is updated to reflect the results of the filterCriteria function. If the filterCriteria function returns false for an element, that element should be removed from currentArray. Otherwise, it is left in currentArray. If filterCriteria is not a function, the returned function (arrayFilterer) should immediately return the value of currentArray with no filtering performed.
- callback - A function that will be called when the filtering is done. callbacktakes the value of currentArray as an argument. Accessing this inside the callback function should reference the value of originalArray. If callback is not a function, it should be ignored. callback does not have a return value.
Step 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