Nodejs Array Rotate rotate(()

Here you can find the source of rotate(()

Method Source Code

'use strict';/*from   w  ww.j ava 2  s .  c  o m*/

// http://stackoverflow.com/questions/1985260/javascript-array-rotate
Array.prototype.rotate = (function() {
    var unshift = Array.prototype.unshift;
    var splice = Array.prototype.splice;

    return function(count) {
        var len = this.length >>> 0;
        count = count >> 0;
        unshift.apply(this, splice.call(this, count % len, len));
        return this;
    };
})();

Related

  1. roll()
    Array.prototype.roll = function() {
        var rand = randomNumber(this.length);
        var tem = [];
        for (var i = rand; i < this.length; i++) {
            tem.push(this[i]);
        for (var i = 0; i < rand; i++) {
            tem.push(this[i]);
        return tem;
    
  2. 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;
    ...
    
  3. 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;
    ...
    
  4. rotate( n )
    Array.prototype.rotate = function( n ) {
      this.unshift.apply( this, this.splice( n, this.length ) )
      return this;
    
  5. 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));
    ...
    
  6. rotate(()
    export function zeroOrOne() {
      return Math.round(Math.random() * 1)
    export function arrayShuffle(a) {
      let j, x, i;
      for (i = a.length; i; i -= 1) {
        j = Math.floor(Math.random() * i);
        x = a[i - 1];
        a[i - 1] = a[j];
    ...
    
  7. rotate(K)
    Array.prototype.rotate = function (K){
      var N = this.length;
      if( N  < 1 || K < 1 || K > N ){
        return this;
      this.reverse(0, N - K - 1);
      this.reverse(N-K, N-1);
      this.reverse();
      return this;
    ...
    
  8. rotate(count)
    Array.prototype.rotate = function(count)
            var len = this.length >>> 0, 
                count = count >> 0; 
            count = ((count % len) + len) % len;
            var copy = this.clone(this);
            push.apply(copy, splice.call(copy, 0, count));
            return copy;
      };
    ...
    
  9. rotate(n)
    Array.prototype.rotate = function(n) {
      this.unshift.apply(this, this.splice(n + 1, this.length))
      return this;
    var arr = [1, 2, 3, 4, 5];
    var arr1 = [1, 2, 3, 4, 5];
    var rotate = function(arr, r) {
      arr.unshift.apply(arr, arr.splice(r + 1, arr.length));
    };
    ...