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
Allie needs to add a long row of numbers. She should enter a
ikadub [295]
I believer the answere is a formula hope this helped
8 0
3 years ago
Read 2 more answers
A data analyst creates a data frame with data that has more than 50,000 observations in it. When they print their data frame, it
Alexandra [31]

A list is an R-object that can have a wide range of different items inside of it, including vectors, functions, and even another list.

The head() function lets you display the first observations in a data frame. The method tail() prints the final observations in your data collection in a manner similar to that. Both head() and tail() print a top line called the 'header', which contains the names of the distinct variables in your data collection. The R language's transform() function is used to alter data. The first parameter is transformed into a data frame. A suitable variable name comprises of letters, numbers and the dot or underline characters. The variable name does not begin with a number but rather with a letter or a dot.

Learn more about variable here-

brainly.com/question/13544580

#SPJ4

7 0
1 year ago
A mobile device user is having problems launching apps and texting. The user touches an app to launch it, but the app icon next
dalvyx [7]

Answer:

The screen protector may be interfering with the touch response

Explanation:

Screen protectors or commonly called screen guards are used to protect phone screens. In case they fall to the ground, these protectors act as shields to keep the phone screen from getting damaged. However screen protectors if not positioned or fixed properly may also cause hindrance to effective touch response as they become barriers to the touch screen.

8 0
2 years ago
How/when should you use student loans?
mote1985 [20]

Answer:

Things you should use your student loan to pay for: Books and supplies; Room and board (meal plans) Off-campus housing; Transportation (gas, bus pass, etc.) Computers; Any equipment you need for classes; Sheets and towels and Things you should not use your student loan to pay for: Pizza and beer for your roomies; Spring break travel; Taking your family out to dinner; Buying a new Mercedes; An outfit for a friend’s wedding; Cleaning services; Entertainment

Explanation:

3 0
2 years ago
What three values must be added to the ipv4 properties of a nic in order for a computer to have basic connectivity with the netw
Y_Kistochka [10]
1. The IP address

2. Subnet mask

3. Default gateway address

It’s values should be added to the NIC properties in order for the computer to have basic network connectivity. This can be done either statically or dynamically with DHCP. An additional value that should be present if the computer is to be used to connect to the Internet is the DNS server value. A computer automatically attempts to locate a DHCP server if configured to do so. A DHCP server address is not used. Finally, NAT is configured on a router, not on a computer host, and speed and duplex settings are NIC hardware settings and not IPv4 properties of the NIC.
8 0
2 years ago
Other questions:
  • When a relationship is established between two or more arrays by using the same subscript to relate entries between the arrays,
    14·2 answers
  • List the steps that you need to locate Microsoft Word on your computer
    7·1 answer
  • To exit Access, click the ____ button on the right side of the Access title bar.
    9·1 answer
  • Suppose that a program asks a user to enter multiple integers, either positive or negative, to do some calculation. The data ent
    13·1 answer
  • A ________ is a question you ask about data stored in a database
    9·1 answer
  • Logical design is tied to a specific hardware and software platform. a. True b. False
    9·1 answer
  • Is there anyone that knows how to work in Microsoft Access and someone that could help me on my test at 11 30am?​
    7·1 answer
  • Pls explain the meaning of the word"INTERNET"​
    5·2 answers
  • Join my FNAF fan club discord
    6·2 answers
  • .....is used to save project in Visual basic .net from file menu
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!