Skip to content

Instantly share code, notes, and snippets.

@anotherxx
Created November 29, 2017 19:40
Show Gist options
  • Save anotherxx/595ac310a321b9ce07f59f7b2757b501 to your computer and use it in GitHub Desktop.
Save anotherxx/595ac310a321b9ce07f59f7b2757b501 to your computer and use it in GitHub Desktop.
let arr1 = [1,2,3,4,5];
let arr2 = [1,2,3,4,5,6,7,8,9,10];
function reverse(arr)
{
var len = arr.length;
var middle = Math.floor(len / 2);
var start = 0;
var end = len - 1;
while(start < middle && end > middle)
{
var temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start += 1;
end -= 1;
}
console.log(arr);
}
reverse(arr1);
reverse(arr2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment