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]
2 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]2 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
Write the technical terms for the following statements: The repeated working capacity of computer.
ozzi

The technical terms for the statement "The repeatedly working capacity of computer" is  known to be "diligence.

<h3>Why is the working capacity of computer" known to be "diligence."?</h3>

The capacity of a computer is known to be one that carry out or performs a lot of task in a repetitive manner without getting tired and as such, one can say the computer is diligent.

Note therefore that The technical terms for the statement "The repeatedly working capacity of computer" is  known to be "diligence.

Learn more about computer from

brainly.com/question/24540334

#SPJ1

8 0
1 year ago
By using the search functionality within a twitter stream, users can filter for:
rosijanka [135]
By using the search functionality within a twitter stream, users can filter for: Tweets containing keywords and key phrases, Tweets from specific users, Tweets containing @mentions, Tweets from specific locations.  <span>The secret to using Twitter effectively is using the Twitter lists. </span>Each Twitter list you create, gives you a different Twitter stream, customized to your liking. It will only include tweets sent out by those accounts you have added to the list
6 0
3 years ago
Write a Tip Calculator in code in VMware Fusion
lisabon 2012 [21]

final \: amount \times percent \: of \: tip = tip \: amount
7 0
2 years ago
Someone please help ASAP will brainlist
Arada [10]

Answer:

i cant help

Explanation:

4 0
2 years ago
Read 2 more answers
You receive an email that appears to legitimately be from your Bank. The email indicates the need for verification of your infor
anzhelika [568]

Answer:

phishing

Explanation:

6 0
2 years ago
Read 2 more answers
Other questions:
  • Which statement best describes antivirus software
    12·2 answers
  • What is the operating system?
    9·1 answer
  • AYUDAAA..... DARÉ TODOS LOS PUNTOS QUE PUEDA.
    15·1 answer
  • When you copy text, the selected text is copied from the original location and placed on the
    9·1 answer
  • Mathematical expression that might link numbers in cells
    14·1 answer
  • Anybody know this question???
    6·1 answer
  • 17. When an industrial electrical circuit requires a 220 VAC single phase power supply, the electric power supply circuit is nor
    7·1 answer
  • What are the defenses to protect against these attacks?
    13·1 answer
  • In java
    6·1 answer
  • Which iteration must have an expression that has a true or false value?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!