reverseArray2.js( by unshift method)

 /* Reverse of an Array


Given
A =[5,8,7,3,10]

Output
A=[10,3,7,8,5]
*/


/////////////////////////////////////////////////////////////////////////////////////////////////////////

let A = [5, 8, 7, 3, 10];

let ans = []; // we are intialising with an empty array to push the elements afterwards.

let i = 0;// intialisation of while loop i= 0,1,2,3,4,5



while (i <= A.length) {

ans.unshift(A[i]);

i++; // increment of while loop

}

console.log(ans);

///////////////////////////////////////////////////////////////////////////////////////////////
TERMINAL:






Comments