Skip to content

Instantly share code, notes, and snippets.

@craftfortress
Last active September 28, 2015 09:07
Show Gist options
  • Save craftfortress/6d85fd03b2195c987990 to your computer and use it in GitHub Desktop.
Save craftfortress/6d85fd03b2195c987990 to your computer and use it in GitHub Desktop.
/// 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);
}
@craftfortress
Copy link
Author

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment