Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. 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.
  2. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions

Question

1. Explain the 2nd world war. 2. Who is the father of history?

Answered: 1 week ago