Nodejs Array Rotate rotate(()

Here you can find the source of rotate(()

Method Source Code

export function zeroOrOne() {
   return Math.round(Math.random() * 1)
}

export function arrayShuffle(a) {
   let j, x, i;/*from  w  w  w.j  av  a 2s.c  o  m*/
   for (i = a.length; i; i -= 1) {
      j = Math.floor(Math.random() * i);
      x = a[i - 1];
      a[i - 1] = a[j];
      a[j] = x;
   }
   return a
}

export function arrayClone(a) {
   return a.slice(0)
}

export function range(min, max) {
   return min + (Math.random() * (max - min))
}

export function randInt(min, max) {
   return Math.round(range(min, max))
}

export function lerp(min, max, alpha) {
   return min + ((max - min) * alpha)
}

Array.prototype.rotate = (function() {
    // save references to array functions to make lookup faster
    var push = Array.prototype.push,
        splice = Array.prototype.splice;

    return function(count) {
        var len = this.length >>> 0, // convert to uint
            count = count >> 0; // convert to int

        // convert count to value in range [0, len)
        count = ((count % len) + len) % len;

        // use splice.call() instead of this.splice() to make function generic
        push.apply(this, splice.call(this, 0, count));
        return this;
    };
})();

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));
    ...
    
  5. rotate(()
    'use strict';
    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;
    ...
    
  6. 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;
    ...
    
  7. 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;
      };
    ...
    
  8. 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));
    };
    ...
    
  9. rotate(n)
    var a =  (function() { var a = []; for (var i = 0; i < 35; i++) { a.push(i) }; return a; }())
    Array.prototype.rotate = function(n) {
      var a = this.concat(this.splice(0, n))
      return a
    a.rotate(12)
    function findI(arr, i) {
      if (arr.length == 2) { return i+1 }
      var k = (arr.length/2).floor(), i = i || 0
    ...