Move Fixed Array Elements - Node.js Array

Node.js examples for Array:Array Operation

Description

Move Fixed Array Elements

Demo Code


function moveFixedArrayElements ( array, begIndex, endIndex, offset )
{
  var i;/*from   w  ww . j  a  v a 2 s .  c om*/

  if ( offset > 0 )
  {
    i = endIndex + offset;
    if ( i >= array.length )
      i = array.length - 1;
    while ( true )
    {
      if ( i < begIndex )
        return;
      array[ i ] = array[ i - offset ];
      i -= 1;
    }
  }
  else
  {
    i = begIndex + offset;
    if ( i < 0 )
      i = 0;
    while ( true )
    {
      if ( i >= endIndex )
        return;
      array[ i ] = array[ i - offset ];
      i += 1;
    }
  }
}

Related Tutorials