Nodejs Array Rotate rotate(()

Here you can find the source of rotate(()

Method Source Code

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;//from   w w  w .  j a  v  a2s. c  om
      count = count % len;
      
      push.apply(this,splice.call(this,count,len));
      // console.log(count%len, splice.call(this,count%len,len), this);
      // unshift.apply(this,splice.call(this,count%len,len));
      
      return this;
   };
})();

var arr=[1,2,3,4,5];
arr.rotate(-2);
console.log(arr);

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(()
    '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(()
    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;
      };
    ...