Nodejs Array Rotate roll()

Here you can find the source of roll()

Method Source Code

Array.prototype.roll = function() {
    var rand = randomNumber(this.length);
    var tem = [];
    for (var i = rand; i < this.length; i++) {
        tem.push(this[i]);//w  w  w  .j av  a 2s  .  c  o m
    }
    for (var i = 0; i < rand; i++) {
        tem.push(this[i]);
    }
    return tem;
}

Related

  1. rotate( ()
    Array.prototype.rotate = (function () {
        var push = Array.prototype.push,
            splice = Array.prototype.splice;
        return function (count) {
            var len = this.length >>> 0,
                count = count >> 0;
            count = ((count % len) + len) % len;
            push.apply(this, splice.call(this, 0, count));
            return this;
    ...
    
  2. rotate( dir )
    Array.prototype.rotate = function ( dir ) {
        var that = this,
            direction = dir !== "ccw",
            columns = that[0].length,
            flat = [],
            tmp = [];
        if ( !(that.length) || !columns ) {
            console.error("incompatible array lengths");
            return false;
    ...
    
  3. rotate( n )
    Array.prototype.rotate = function( n ) {
      this.unshift.apply( this, this.splice( n, this.length ) )
      return this;
    
  4. rotate(()
    Array.prototype.rotate = (function(){
      var unshift = Array.prototype.unshift,
      push=Array.prototype.push,
      splice=Array.prototype.splice;
      return function(count){
        var len=this.length >>>0,
        count = count >> 0;
        count = count % len;
        push.apply(this,splice.call(this,count,len));
    ...