Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. /**
  2. * Fast method
  3. */
  4. function shift(arr, direction, n) {
  5. var times = n > arr.length ? n % arr.length : n;
  6. return arr.concat(arr.splice(0, (direction > 0 ? arr.length - times : times)));
  7. }
  8.  
  9. /**
  10. * Slow method
  11. */
  12. function shift2(arr, direction, n) {
  13. for (var i = n; i > 0; --i) { (direction > 0 ? arr.unshift(arr.pop()) : arr.push(arr.shift())); }
  14. return arr;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement