-Annie-

RotateArray

Jun 2nd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.     "use strict";
  3.     let numberOfRotations = arr.pop();
  4.     numberOfRotations = Number(numberOfRotations);
  5.     numberOfRotations %= arr.length;
  6.  
  7.     for(let i = 0; i < numberOfRotations; i++) {
  8.         let lasElement = arr.pop();
  9.         arr.unshift(lasElement);
  10.     }
  11.  
  12.     console.log(arr.join(' '));
  13. }
Advertisement
Add Comment
Please, Sign In to add comment