Array.reverse() | array.reverse();
| ready |
while push then slice | var left = 0;
while (left < length)
{
array.push(array[length - 1 - ++left]);
array.splice(length - 1 - left, 1);
}
| ready |
while forward | var left = 0;
while (left < length)
{
var right = length - 1 - left;
array.push(array[right]);
array.splice(right, 1);
left += 1;
}
| ready |
for push then slice | var len = length;
for (len -= 2; len > -1; len -= 1)
{
array.push(array[len]);
array.splice(len, 1);
}
| ready |
for push | var result = [];
var i = null;
for (i = length - 1; i >= 0; i -= 1)
{
result.push(array[i]);
}
| ready |
for swap | var left = null;
var right = null;
for (left = 0, right = length - 1; left < right; left++, right--)
{
var temporary = array[left];
array[left] = array[right];
array[right] = temporary;
}
| ready |
for swap half | var left = null;
var right = null;
for (left = 0; left < length / 2; left += 1)
{
right = length - 1 - left;
var temporary = array[left];
array[left] = array[right];
array[right] = temporary;
}
| ready |
XOR swap | var i = null;
var r = null;
for (i = 0, r = length - 1; i < r; i += 1, r -= 1)
{
var left = array[i];
var right = array[r];
left ^= right;
right ^= left;
left ^= right;
array[i] = left;
array[r] = right;
}
| ready |
XOR swap half | var i = null;
var r = null;
for (i = 0; i < length / 2; i += 1)
{
r = length - 1 - i;
var left = array[i];
var right = array[r];
left ^= right;
right ^= left;
left ^= right;
array[i] = left;
array[r] = right;
}
| ready |
destructuring | var left = null;
var right = null;
for (left = 0, right = length - 1; left < right; left += 1, right -= 1)
{
[array[left], array[right]] = [array[right], array[left]];
}
| ready |
destructuring half | var left = null;
var right = null;
for (left = 0; left < length / 2; left += 1)
{
right = length - 1 - left;
[array[left], array[right]] = [array[right], array[left]];
}
| ready |
Reverse looping | var tempArray = [];
for(var i = array.length-1, size=array.length-1; i >= 0; i--)
{
tempArray[size-i] = array[i];
}
array = tempArray;
| ready |
While Swap | var left = 0;
var right = length-1;
var temporary;
while (left < right)
{
temporary = array[left];
array[left] = array[right];
array[right] = temporary;
left += 1;
right -= 1;
}
| ready |