rotate

by thewolff

JavaScript

const arr = [1,2,3,4,5,6];
 
Array.prototype.rotate = function(n) {
    while (this.length && n < 0) n += this.length;
    this.push.apply(this, this.splice(0, n));
    return this;
}

console.log(arr.rotate(2))