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 | for (length -= 2; length > -1; length -= 1) {
array.push(array[length]);
array.splice(length, 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 += 1, right -= 1) {
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 |
traverse towards center | var first = null;
var last = null;
var tmp = null;
for (first = 0, last = length - 1; first < length / 2; first++, last--) {
tmp = array[first];
array[first] = array[last];
array[last] = tmp;
}
| ready |