Last active
September 28, 2015 09:07
-
-
Save craftfortress/6d85fd03b2195c987990 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// REVERSE ARRAY | |
var array = [1,2,3,4,5,6,7,8,9]; | |
var leftMark = 0; | |
var rightMark = array.length; | |
reverseArray(array,leftMark,rightMark); | |
function reverseArray(array, leftMark, rightMark){ | |
while(leftMark != rightMark){ | |
temp = array[leftMark]; | |
array[leftMark] = array[rightMark]; | |
array[rightMark] = temp; | |
leftMark++; | |
rightMark--; | |
} | |
console.log(array); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function destructuringSwapHalf(array)
{
var left = null;
var right = null;
var length = array.length;
for (left = 0; left < length / 2; left += 1)
{
right = length - 1 - left;
[array[left], array[right]] = [array[right], array[left]];
}
return array;
}