reverseArray1.js ( by push 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 = A.length - 1;// intialisation of while loop i= 4,3,2,1,0



while (i >= 0) {

ans.push(A[i]);

i--; // decrement of while loop

}

console.log(ans);

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





Comments