Nodejs Array Rotate rotate_copy(begin, middle, end)

Here you can find the source of rotate_copy(begin, middle, end)

Method Source Code

/**// w ww .j  a  v  a  2 s .c  o  m
 * @file rotate_copy.js, Contains the rotate_copy implementation.
 *
 * Copyright (C) 2011 Thomas P. Lahoda
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */
Array.prototype.rotate_copy = function (begin, middle, end) {
  var back = this.slice (begin, middle - begin);
  back.unshift (0);
  back.unshift (end - middle);
  var front = this.slice (middle, end);
  front.splice.apply (front, back);
  return front;
};

Related

  1. 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;
      };
    ...
    
  2. 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));
    };
    ...
    
  3. 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
    ...
    
  4. rotate(times)
    Array.prototype.rotate = function(times) {
      if (times < 0) {
        var last = arr.pop
        return arr.unshift(last)
    function solution (numbers, times) {
      for (var i = 0; i < times; i++) {
        numbers.rotate
    ...
    
  5. rotateArray(n)
    Array.prototype.rotateArray = function (n) {
        let firstArray = [];
        let secondArray = [];
        for (let i = this.length - 1; i > this.length - n - 1; i--) {
            firstArray.unshift(this[i]);
        for (let j = 0; j < this.length - n; j++) {
            secondArray[secondArray.length] = this[j];
        return firstArray.concat(secondArray);
    function createArray() {
        let valuesStr = prompt("Enter an Array : ");
        let arrayStr = valuesStr.split(" ");
        let array = [];
        for (let i = 0; i < arrayStr.length; i++) {
            if (arrayStr[i] )
            array[array.length] = Number(arrayStr[i]);
        return array;
    let array = createArray();
    console.log(array.rotateArray(3));