/*
Program to cyclically rotate an array by one
Difficulty Level : Basic
Last Updated : 26 Mar, 2021
GeeksforGeeks - Summer Carnival Banner
Given an array, cyclically rotate the array clockwise by one. 
Examples: 
 

Input:  arr[] = {1, 2, 3, 4, 5}
Output: arr[] = {5, 1, 2, 3, 4}
 

Recommended: Please solve it on “PRACTICE” first, before moving on to the solution.
Following are steps. 
1) Store last element in a variable say x. 
2) Shift all elements one position ahead. 
3) Replace first element of array with x.
*/

const rotate = (arr) => {
  let a = [arr[arr.length - 1]];
  for (let i = 0; i < arr.length - 1; i++) {
    a.push(arr[i]);
  }
  return a;
};
console.log(rotate([1, 2, 3, 4, 5])); 
by