Challenge: Right Rotate an Array by n

Given an array, can you rotate its elements from right to left by one index? Implement your solution in JavaScript and see if your code runs successfully!

Problem Statement #

Implement a function rightRotate(arr,n) that will rotate the given array by n.

Input #

An array and a number by which to rotate that array

Output #

The given array rotated by n elements

Sample Input #

arr = [1,2,3,4,5]
n = 3

Sample Output #

arr = [3,4,5,1,2]

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.