Node.js examples for Array:Array Value
Rotate array by the given steps
/* rotate array by the given steps */ Array.prototype.rotate = function(p) { for(var l = this.length, p = (Math.abs(p) >= l && (p %= l), p < 0 && (p += l), p), i, x; p; p = (Math.ceil(l / p) - 1) * p - l + (l = p)) for(i = l; i > p; x = this[--i], this[i] = this[i - p], this[i - p] = x); };