Todorov_Stanimir

03. Rotate Array Arrays - More Exercise

Jun 10th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function rotateArray(input) {
  2.     let numberRotation = Number(input.pop());
  3.     if (numberRotation > 0 && input.length > 0) {
  4.         for (let i = 1; i <= numberRotation; i++) {
  5.             let currentElement = input.pop();
  6.             input.unshift(currentElement);
  7.         }
  8.         console.log(input.join(' '));
  9.     } else {
  10.         console.log('Empty');
  11.     }
  12. }
Advertisement
Add Comment
Please, Sign In to add comment