Updated 3 years ago
Arrays
Ques: Reversing an Array!
1. Iterative Way
arr1 = [1,2,3,4,5,6,7,8]
arr2 = [1,3,5,7,8]
third_var = arr1[0]
arr1[0] = arr1[7]
arr1[7] = third_var
arr1
[8, 2, 3, 4, 5, 6, 7, 1]
arr1[0], arr1[7] = arr1[7], arr1[0]
arr1
[8, 2, 3, 4, 5, 6, 7, 1]