Objective

Create a function to reverse a given array, in-place.

Difficulty

Very easy

Description

Consider the following array of numbers:

var nums = [1, 5, 9];

If we reverse this array, the order of elements will simply get reversed.

That is, the first element will become the last element; the second element will become the second-last element; the third element will become the third-last element; and so on and so forth.

In this exercise, you have to create a function arrayReverse() that reverse a given array.

Here's the signature of the function:

function arrayReverse(arr) {
   // Your code here.
}

The given parameter arr is the array to reverse.

Note that the function should mutate the array in-place, i.e. the original array should be modified. Moreover, the function should also return the modified array.

Below shown is an illustration of the usage of the function:

var nums = [1, 5, 9]
undefined
arrayReverse(nums)
[9, 5, 1]
nums
[9, 5, 1]

As can be seen here, the call to arrayReverse() returns the reversed array [9, 5, 1], and the actual array nums is also modified as is confirmed by the third statement.