Answered step by step
Verified Expert Solution
Question
1 Approved Answer
a . Problem 1 . Create an array of 3 0 random numbers that range between 1 and 1 0 0 . Then, write a
a Problem Create an array of random numbers that range between and Then, write a function that will receive a number from the user and determine if that number exists in the array or not.
For instance, assume the array is:
Now, assume the user enters the program should output true. But, if the user
enters the program should output false.
Approach:
We will be implementing this method in two different ways. Both will be recursive.
First, implement a method called findA where is the number we are looking for and is an array. In the body of the function, compare with the FIRST item that is in the array. If this first item is equal to return true. If not, remove the first item from A and call findA on the revised list. If you call find on an empty list, you will want to return false.
Writing any explicit loop in your code results a for this question. Remember to provide pre and postconditions. How many recursive calls will you need to search the entire list?
Next, copy the following trace table in your word file and trace the input values to the function findA A for when A and are initially and respectively. As a guideline, we have populated the tables with the values for the first calls and the corresponding returned values for each of those calls. Note that in this example, the call numbers will be populated top down ie time elapses from row to row while returned values are populated bottomup ie the value in row is returned before the value in row You may want to use console.log to observe these values when you write your solution.
tablecall#tablevalue returned tothis callTRUETRUE
Need javascript code & trace table too
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