Write a function reverseInPlace(arr) that reverses an array in place: the first element changes places with the last one, the second with the one before the last, and so on.
arr is an array of numbers or strings. It can be empty.arr itself (mutate it), do not build a new array.arr, not a copy.reverse() or toReversed(), also not on a copy of the array. Hidden tests replace them with functions that throw an error.Use two indexes: one from the start and one from the end. Swap the elements at each index pair and move the indexes toward each other.
reverseInPlace([1, 2, 3, 4, 5])Returns [ 5, 4, 3, 2, 1 ]
reverseInPlace(['a', 'b', 'c', 'd'])Returns [ 'd', 'c', 'b', 'a' ]
reverseInPlace([])Returns []
reverseInPlace([ 1, 2, 3, 4, 5 ])[ 5, 4, 3, 2, 1 ]reverseInPlace([ 1, 2, 3, 4 ])[ 4, 3, 2, 1 ]Hidden tests run on Submit.