Will give brainliest and good amount of points, no false answers.I am using javascript for school and I still have no idea what I am doing. Can someone help? The instructions are,

A key step in many sorting algorithms (including selection sort) is swapping the location of two items in an array. Here's a swap function that looks like it might work, but doesn't:
-the code prints out [9, 9, 4] when it should print out [9, 7, 4].

Fix the swap function.

Hint: Work through the code line by line, writing down the values of items in the array after each step. Could you use an extra temporary variable to solve the problem that shows up?

Once implemented, uncomment the Program.assertEqual() at the bottom to verify that the test assertion passes.


the layout for javascript is,

var swap = function(array, firstIndex, secondIndex) {
array[firstIndex] = array[secondIndex];
array[secondIndex] = array[firstIndex];
};

var testArray = [7, 9, 4];
swap(testArray, 0, 1);

println(testArray);

//Program.assertEqual(testArray, [9, 7, 4]);

Answers

Answer 1
Answer:

The problem with the swap function is that it loses the value at the first index, as soon as it gets overwritten by the value at the second index. This happens in the first statement. To fix it, you need a helper variable.

First you're going to "park" the index at the first index in that helper variable, then you can safely overwrite it with the value at the second index. Then finally you can write the parked value to the second index:

var swap = function(array, firstIndex, secondIndex) {

let helper = array[firstIndex];

array[firstIndex]  = array[secondIndex];

array[secondIndex] = helper;

};

I hope this makes sense to you.


Related Questions

Proper Goal Setting requires the goals to be:Difficult to achieveRealisticNot dependent upon any deadline for completion
Who produced the IR 600 system in 1978?a) Kawasaki Roboticsb) KUKAc) Unimated) AMF
What is an example of a dedicated computer system?
A microphone is a type of electronic.True/Faulse
Which of the given original work is protected by the copyright lawNBC logoMonsanto’s generically modified seeds BMW logoThe fault in our starts by John green

A site that has advertisements (ads) it can only monetize the number of clicks by ip? for example, A person who clicks on the site ad, the ad will only monetize if the person who clicked to display your ip? or is it possible to monetize with ads without even having to find out the person's ip?

Answers

it is possible to monetuze wuth ads without even haveing to f8nd out the persons ip
it is possible. hope you get good grades in school

Computer viruses often spread by means of what?

Answers

Emails, pop-ups and advertisements usually spread computer viruses.

Answer:

C

Explanation:

a security system uses sensors at every door and window which will set off an alarm if any one of them is opened. there is also a keypad by an entry door to turn on or turn off the system. describe how these components can be wired in a combination circuit to provide the needed security.

Answers

Wire the motion sensors in rooms and in between rooms in a series circuit and connect the sensors on all the doors and windows in a parallel circuit.
The reasoning being, if you open a window or door the sensors will trip and the circuit will break if the sensors are wired in series, however, if the sensors are connected in parallel the sensors can be opened and the alarm system will not stop working. By connecting the stationary sensors in series, you will prevent people from disconnecting these sensors without the alarm going off.

It is the student’s responsibility to meet the expectations identified by a rubric.Please select the best answer from the choices provided

T
F

Answers

Answer:

Your correct answer is TRUE

It is the student’s responsibility to meet the expectations identified by a rubric. The given statement is true.

What is motivation?

Motivation is the action or act of helping others find the strength and energy to carry out a task with enthusiasm. Just like in the case, above, the expectations were at variance with the reality. Hence Dana helped them by revising the assignment.

Next, add transition words to make the essay more logical and easier to read. Finally, look for places where the repetition of words can be eliminated with the use of synonyms, or by rephrasing. By following these steps, the essay will become more cohesive and the writing more concise and effective.

Learn more about Transition Words:

brainly.com/question/29775567

#SPJ5

Which email writing etiquette should Ariel follow to let people know that she received their message? A. reply to their messages immediately
B. use formal language
C. specify the email's intent in the subject field
D. be direct when writing the reply

Answers

I'm pretty sure its either A or D

Which of the following actions can NEGATIVELY impact your credit score?

Answers

The answer to the question stated above is "forget to pay the cable bill"
>Payment history influences your credit score the most.

Here are the following choices to this question:
 A-dispute an item on your credit report 
B- forget to pay the cable bill 
C- pay all bills in cash 
D- use small amount of your available credit