Question: Consider the following piece of JavaScript: function swap ( array , index 1 , index 2 ) { var index 2 ] ; array [

Consider the following piece of JavaScript:
function swap(array,index1,index2){
var index2];
array[index2]= array[index1];
array [index1]=x;
return array;
}
var arr=[1,2,2,3];
swap (arr,1,2);
swap (arr,2,3);
console.log(arr);
What is printed to the console?
Rremember that in JavaScript arrays, the first index is 0.
[1,2,3,2]
[3,2,2,1]
[2,2,3,1]
[1,3,2,2]
 Consider the following piece of JavaScript: function swap(array,index1,index2){ var index2]; array[index2]=

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!