1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
RoseWind [281]
3 years ago
11

Write syntactically correct Javascript code to sort an array of sub-arrays containing integers using the sort and reduce array f

unctions as described below. You will sort the sub-arrays in ascending order by the maximum value found in each sub-array. Your solution would be executed in the following manner:
Computers and Technology
1 answer:
masha68 [24]3 years ago
3 0

The question is incomplete. The complete question is:

Write syntactically correct Javascript code to sort an array of sub-arrays containing integers using the sort and reduce array functions as described below. You will sort the sub-arrays in ascending order by the maxium value found in each sub-array. Your solution would be executed in the following manner:

var x = [ [ 2 , 5 , 1 ], [ 1 , 23 ] , [ 3 ] , [ 22, 16, 8 ] ] ;

x.sort(compare);

will result in variable x containing [ 3 ] , [ 2, 5, 1], [ 22 , 16 , 8], [ 1 , 23 ] ]. The maximum value of each sub-array is shown here in bold. Your solution must be written so that when run with the code above, x will contain the sorted array.

Answer:

function compare(a , b) {

var max1 = Math.max(...a); //get the max in array a

var max2 = Math.max(...b); //get the max in array b

return max1 - max2;

}

var x = [ [ 2 , 5 , 1 ], [ 1 , 23 ] , [ 3 ] , [ 22, 16, 8 ] ] ;

x.sort(compare);

Explanation:

Given an array A positive integers, sort the array in ascending order such that element in given subarray which start and end indexes are input in unsorted array stay unmoved and all other elements are sorted.

An array is a special kind of object. With the square brackets, access to a property arr[0] actually come from the object syntax. This is essentially the same as obj[key], where arr is the object, while numbers are used as keys.

Therefore, sorting sub-array in ascending order by the maxium value found in each sub-array is done:

function compare(a , b) {

var max1 = Math.max(...a); //get the max in array a

var max2 = Math.max(...b); //get the max in array b

return max1 - max2;

}

var x = [ [ 2 , 5 , 1 ], [ 1 , 23 ] , [ 3 ] , [ 22, 16, 8 ] ] ;

x.sort(compare);

You might be interested in
When the animation and the graphic designs are used to sell products or services, it is known as multimedia advertising. The sta
Aliun [14]

\qquad \qquad\huge \underline{\boxed{\sf Answer}}

The Correct choice is " True "

When the animation and the graphic designs are used to sell products or services, it is known as multimedia advertising.

3 0
3 years ago
Suppose an ArrayList list contains {"red", "red", "green"}. What is the list after the following code? String element = "red"; f
maksim [4K]

Answer:

The output of the given code as follows:

<u>Output: </u>

{"red", "green"}

Explanation:

  • In the given code a list is defined, which contains three elements, which are "red, red, and green". In the next step, a string variable "element" is initialized with a value that is "red".
  • Then a for loop is declared, that counts list size, and inside the loop and if block is declared, that compares the value list with element variable then it removes from the list.  

8 0
3 years ago
For a data structure, such as a stack, who is responsible for throwing an exception if the stack is empty and a pop() is called:
lubasha [3.4K]

Answer:

D. End-User Programmer.

Explanation:

A stack data structure is used to holds data for programs. The first data to go into a stack is always the last to be extracted (First-in-Last-out). Data is read into the stack with the push function and retrieved with the pop function.

When the stack is empty, it means there are no data left to pop from it. If a pop function is issued at this time, the program conventionally throws an error, there is no need for the end-user to write an exception handler for it because the end-user programmer has done that already.

4 0
3 years ago
g Consider a TCP connection between Host A and Host B. Suppose that the TCP segments traveling from Host A to Host B have source
Inga [223]

Answer:

Source port number and destination port numbers for segment travelling from HOST B to HOST A are : Source port number is y , and Destination port number is x.

Explanation:

Because in problem statement it given that the TCP segments traveling from Host A to Host B have source port number x and destination port number y. So it is clear that that Host A has a port named x and Host B has a port named y and when segments travels from Host B to Host A the Host B's port becomes source and Host A's port becomes source.

5 0
3 years ago
How can i fix this, if i log in my acc it keeps saying wrong nickname or pass. even though my email and pass is correct
Oksanka [162]

Answer:

미안해요. 나는 우리가 단지 부동일 중 하나를 모르지만 그것을 해결하는 방법을 모른다!.

8 0
3 years ago
Other questions:
  • Alex leads a team of eight members. Arrange his tasks in sequential order of phases of group dynamics. What are the stages in gr
    13·1 answer
  • Using C++, Write a full class definition for a class named Acc1, containing no constructors, functions, or data members (i.e., a
    12·2 answers
  • Pam is using the Outline view in PowerPoint. She would like to reposition
    13·1 answer
  • The Python print function
    9·1 answer
  • Edhesive 1.7 code practice question 1
    8·1 answer
  • What do you believe is the future of certification?
    7·1 answer
  • Anyone wanna teach me how to get better at Rocket League?
    7·2 answers
  • Which of the following is true of a procedure? Check all that apply.
    10·2 answers
  • What does a production proposal provide ?
    7·2 answers
  • Which of the formulas below are valid? Select all that apply?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!