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
A(n) __________ can include a computer's full operating system, applications, and system settings, including security and config
babymother [125]

Solution:

It is done by Operating system.

An Operating system is system software that manages computer hardware and software resources and provides common services for computer programs.

Time-sharing operating systems schedule tasks for efficient use of the system and may also include accounting software for cost allocation of processor time, mass storage, printing, and other resources.

For hardware functions such as input and output and memory allocation, the operating system acts as an intermediary between programs and the computer hardware, although the application code is usually executed directly by the hardware and frequently makes system calls to an OS function or is interrupted by it. Operating systems are found on many devices that contain a computer – from cellular phones and video game consoles to web servers and supercomputers.


5 0
3 years ago
If you were teaching a fellow student to use software for the first time and the software had many built-in hotkeys, would you f
Liula [17]

Answer:

Hotkey commands

Explanation:

It would be easier and more efficient in the long run to use hotkeys.

5 0
3 years ago
Sara is writing a program to input her monthly phone bills and output the month name and amount for the month with maximum amoun
Andru [333]

Answer:

# include <conio.h>

#include <iostream.h>

using namespace std;

main()

{

int billamount[12];

char monthname["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

<em>for (int month = 1 ; month<=12; month++)</em>

<em>{</em>

<em>cout<<"Enter the amount of bill for the month"<<month;</em>

<em>cin>>billamount[month];</em>

<em>}</em>

for (i=0; i<= 12; i++)

{

if (billamount[0]<billamount[i])

billamount[0]=billamount[i];

monthname[0]=monthname[i];

}

<em>cout<<"Maximum months phone bill"<<monthname[0]<<"="<<billamount[0]</em>

<em />

getch();

}

6 0
3 years ago
The recheck document button, which resets the spelling and grammar checker to flag previously ignored errors, is located in the
kumpel [21]
The answer is b and c
7 0
3 years ago
What is one way you might code-switch when posting a comment to a class discussion?
irina [24]

Answer:

The term code switching has been expanded and can encapsulate in any situation that speaker find to be switch from vocabulary.

Explanation:

It is a truly remarkable skill when you communicate your emotions, thoughts and opinion to others. It does not mean that we just to communicate our language but our language influence our thought, emotions and language and self identity.

we communicate our culture that is reflected in our language. Our language tells that who we are and from where we comes.

Code switching is related to the speakers alternates use of multiple language. in the one communication.

For example: Grace for beautiful gift ( Esta awesome).

7 0
2 years ago
Other questions:
  • A ____________ variable is available throughout a program.
    7·1 answer
  • When should an individual consider entering parenthood?
    5·1 answer
  • In order to plan George's birthday, his father gave him a list of people who attended his birthday for the last five years. What
    5·1 answer
  • To remove text from a specific location and keep it to use again, you should select ___
    6·1 answer
  • Im bored anyone up for a convo? lets talk.. =D
    7·2 answers
  • Hey friends,<br><br> What is a IT form?<br><br> thanks
    12·1 answer
  • Por favor alguem poderia me falar qual PC e melhor: Computador Gamer Fox PC FPS Intel Core i5 8GB (GeForce GTX 1050Ti 4GB GDDR5)
    15·1 answer
  • 2. What is the name for an action performed by the VR Robot?
    7·2 answers
  • The scientific process is most similar to what
    10·1 answer
  • Which unit of binary storage has a size that is processor dependent?.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!