Nodejs Array Move move(old_index, new_index)

Here you can find the source of move(old_index, new_index)

Method Source Code

/**//from   w ww .j av a 2s .c o m
 * Moves array's element from old_index to new_index
 * @memberof module:ArrayFunctions
 * @param {number} old_index Old index
 * @param {number} new_index New index
 * @returns {Array}
 */
Array.prototype.move = function (old_index, new_index) {
    while (old_index < 0) {
        old_index += this.length;
    }
    while (new_index < 0) {
        new_index += this.length;
    }
    if (new_index >= this.length) {
        var k = new_index - this.length;
        while ((k--) + 1) {
            this.push(undefined);
        }
    }
    this.splice(new_index, 0, this.splice(old_index, 1)[0]);
    return this;
};

Related

  1. move(old_index, new_index)
    "use strict";
    Array.prototype.move = function (old_index, new_index) {
      if (new_index >= this.length) {
        var k = new_index - this.length;
        while (k-- + 1) {
          this.push(undefined);
      this.splice(new_index, 0, this.splice(old_index, 1)[0]);
    ...
    
  2. move(old_index, new_index)
    function pad(num, size){
        var s = "0000000000000000000" + num;
        return s.substr(s.length-size);
    Array.prototype.move = function (old_index, new_index) {
        if (new_index >= this.length) {
            var k = new_index - this.length;
            while ((k--) + 1) {
                this.push(undefined);
    ...
    
  3. move(old_index, new_index)
    Array.prototype.move = function (old_index, new_index) {
        if (new_index >= this.length) {
            var k = new_index - this.length;
            while ((k--) + 1) {
                this.push(undefined);
        this.splice(new_index, 0, this.splice(old_index, 1)[0]);
        return this; 
    ...
    
  4. move(old_index, new_index)
    Array.prototype.move = function (old_index, new_index) {
        if (new_index >= this.length) {
            var k = new_index - this.length;
            while ((k--) + 1) {
                this.push(undefined);
        this.splice(new_index, 0, this.splice(old_index, 1)[0]);
        return this; 
    ...
    
  5. move(old_index, new_index)
    "use strict";
    Array.prototype.move = function (old_index, new_index) {
        if (new_index >= this.length) {
            var k = new_index - this.length;
            while ((k--) + 1) {
                this.push(undefined);
        this.splice(new_index, 0, this.splice(old_index, 1)[0]);
    ...
    
  6. move(old_index, new_index)
    function randomNumberBetween(x, y) {
        return (Math.random() * (y - x)) + x;
    $.fn.exists = function(callback) {
      var args = [].slice.call(arguments, 1);
      if (this.length) {
        callback.call(this, args);
      return this;
    ...
    
  7. move(old_index, new_index)
    Array.prototype.move = function (old_index, new_index) {
      if (new_index >= this.length) {
        var k = new_index - this.length;
        while ((k--) + 1) {
          this.push(undefined);
      this.splice(new_index, 0, this.splice(old_index, 1)[0]);
      return this;
    ...
    
  8. move(old_index, new_index)
    Array.prototype.move = function (old_index, new_index) {
        while (old_index < 0) {
            old_index += this.length;
        while (new_index < 0) {
            new_index += this.length;
        if (new_index >= this.length) {
            var k = new_index - this.length;
    ...
    
  9. move(pos1, pos2)
    Array.prototype.move = function(pos1, pos2) {
      var i, tmp, _ref, _ref2;
      tmp = this[pos1];
      if (pos1 < pos2) {
        for (i = pos1, _ref = pos2 - 1; pos1 <= _ref ? i <= _ref : i >= _ref; pos1 <= _ref ? i++ : i--) {
          this[i] = this[i + 1];
      } else {
        for (i = pos1, _ref2 = pos2 + 1; pos1 <= _ref2 ? i <= _ref2 : i >= _ref2; pos1 <= _ref2 ? i++ : i--) {
    ...