Question: The JavaScript code segment below calls a function magicArray that has three array parameters ( a , b , and c ) of the same

The JavaScript code segment below calls a function magicArray that has three array parameters (a, b, and c) of the same length. The function is intended to assign the smaller of the corresponding elements in arrays a and b to the corresponding elements of c. For example, if
a[1]=3 and b[1]=5, then c[1]=3 because 3<5. If the two items compared are equal, either
can be assigned to array c. The code segment below also calls a function printArray which prints the elements of an array in a vertical format. You can assume that the arrays have the same number of elements. Your code should work as intended for arrays of any size.
function magicArray (a, b, c){
Missing Code
}
function printArray (arr){
//Missing Code
Program Run
Array a:
1
11
8
4
Example 1
Arrav a
1
11
}
var a = new Array(1,11,8,4);
var b = new Array(9,17,6,8);
var c = new Array(0,0,0,0);
magicArray (a, b, c);
document.write( "Array a:
");
printArray (a);
document.write("Array b:
");
printArray (b);
document.write ("Array c:
");
printArray(c);
4
Arrav b
9
17
6
8
Array c
1
11
6
4
Array b:
9
17
6
8
Array c:
1
11
6
4
Example2
Array a
1
2
4
1
17
Array b
5
6
7
9
21
Array c
1
2
3
4
1
17
In the textbox below, you are to type the code for the two functions magicArray and printArray so that they work as intended as shown in the above program run and examples.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The question requires writing two functions magicArray and printArray in JavaScript Lets break down ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!