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
In which of the following situations may the taxpayer take an education expense on Schedule C? a. Henry, a self-employed adminis
daser333 [38]

Answer:

Henry, an administrative assistant, is taking an advanced Word computer program class through an adult school program.  

Explanation:

4 0
3 years ago
When you're writing for mobile devices, use ________ to present the most important information first and provide successive laye
kogti [31]

Answer:

An inverted pyramid style.

6 0
3 years ago
A(n) ____ is a web-based repository of information that anyone can access, contribute to, or modify.
IgorLugansk [536]

Wiki exists as a web-based repository of information that anyone can access, contribute to, or alter.

<h3>What is a wiki?</h3>

A wiki exists as a combined tool that authorizes students to donate and change one or more additional pages of course-connected materials. Wikis exist as collaborative in nature and promote community-building within a course. Essentially, a wiki exists as a web page with an open-editing system.

A wiki exists as a website or online resource that can be revised by multiple users. Some wikis, such as Wikipedia, exist publicly accessible. Others exist utilized by associations to manage data in-house, allowing teams to efficiently share knowledge and work together better effectively.

A wiki exists on a Web site that authorizes users to add and update content on the site utilizing their own Web browser. This exists created probable by Wiki software that operates on the Web server. Wikis finish up being driven mainly by a combined effort of the area visitors.

To learn more about wiki refer to:

brainly.com/question/25153373

#SPJ4

5 0
2 years ago
What do newly PivotTables look like?
adell [148]

Answer:

Answer is in attached image!

Explanation:

8 0
3 years ago
Effective feedback should focus on the behavior, not the person.<br><br> True<br> False
Aleonysh [2.5K]
Your answer is False my fellow samurai
5 0
3 years ago
Read 2 more answers
Other questions:
  • How can investors receive compounding returns
    13·1 answer
  • You support Richman Investments, a brokerage firm that employs 20 brokers. Each broker has his own client computer, and the firm
    15·1 answer
  • A router is a device that addresses a packet on a network to the next router along the line. Under which layer of the OSI model
    5·1 answer
  • A flat-panel detector is exposed with nothing between the x-ray tube and detector. 5 images were acquired on 5 different days us
    6·1 answer
  • Can someone help please
    12·1 answer
  • Should the federal government have bug bounty programs? Why or why not?
    9·2 answers
  • The goal of this problem is to cover all roads with cameras. A camera placed at a station can cover all the roads connected to i
    9·1 answer
  • Does anyone know this? Can someone please help me? I’ll give brainliest!!
    7·1 answer
  • Please help!!! Question 8
    14·1 answer
  • What do we call the software which programmers use to program?​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!