Reverse an array

Easy
11
70.0% Acceptance

You have been asked to write a function called reverseAnArray(arr) that takes in one array arr as the argument. The function should reverse the order of the elements in the array and return the reversed array.

Instructions

  • If the input array is empty, then return an empty array.
  • The input array will only contain strings and numbers.

Example test cases

reverseAnArray([1, 2, 3, 4, 5]) // Output: [5, 4, 3, 2, 1] reverseAnArray(['e', 'd', 'c', 'b', 'a']) // Output: ['a', 'b', 'c', 'd', 'e'] reverseAnArray([1, 2]]) // Output: [2, 1]

Hints

  • You can create a new array, loop over the input array arr from the last index and push each element to the new array.
  • You can use the built-in .reverse() method.