Nodejs Array Move Down moveElement(index, delta)

Here you can find the source of moveElement(index, delta)

Method Source Code

/*//from w  ww  . j a v a 2s. co  m
    App Utilities
*/

Array.prototype.moveElement = function (index, delta) {
    var index2, temp_item;

    // Make sure the index is within the array bounds
    if (index < 0 || index >= this.length) {
        return false;
    }

    // Make sure the target index is within the array bounds
    index2 = index + delta;
    if (index2 < 0 || index2 >= this.length || index2 == index) {
        return false;
    }

    // Move the elements in the array
    temp_item = this[index2];
    this[index2] = this[index];
    this[index] = temp_item;

    return true;
};

Array.prototype.getPageData = function(data, pageSize, currentPageNo)
{
    var start = currentPageNo * pageSize,
        end = (currentPageNo * pageSize + pageSize) > data.length
                ? data.length
                : (pageSize * pageSize + pageSize);

    return data.slice(start, end);
};

Related

  1. moveDown(element, offset)
    Array.prototype.moveDown = function(element, offset) 
        var index = this.indexOf(element); 
        var newPos = index + (offset || 1);
        if(index === -1) { throw new Error("Element not found in array"); }
        if(newPos >= this.length) { newPos = this.length; }
        this.splice(index, 1);
        this.splice(newPos,0,element);
    };
    ...
    
  2. moveDown(value, by)
    Array.prototype.moveDown = function(value, by) {
      var index = this.indexOf(value);
      if (index === -1) {
        throw new Error('Item not found');
      var newPos = index + (pos || 1);
      if (newPos >= this.length) {
        newPos = this.length;
      this.splice(index, 1);
      this.splice(newPos, 0, value);
    
  3. moveDown(value, by)
    Array.prototype.moveDown = function(value, by) {
        var index = this.indexOf(value),
            newPos = index + (by || 1);
        if(index === -1)
            throw new Error("Element not found in array");
        if(newPos >= this.length)
            newPos = this.length;
        this.splice(index, 1);
        this.splice(newPos,0,value);
    ...