Posted By

Pjotor on 05/04/17


Tagged

array prototype


Versions (?)

Array Rotate


 / Published in: JavaScript
 

URL: http://pjotor.com

Returns a clone of the array, rotated n steps. Supports negative direction.

  1. Array.prototype.rotate = function (count = 0, clone = this.slice()) {
  2. return clone.splice(count%clone.length).concat(clone);
  3. }

Report this snippet  

You need to login to post a comment.