Skip to content

Instantly share code, notes, and snippets.

@edrohler
Created March 4, 2016 21:03
Show Gist options
  • Save edrohler/276180eae493f41fbff3 to your computer and use it in GitHub Desktop.
Save edrohler/276180eae493f41fbff3 to your computer and use it in GitHub Desktop.
Reverse an Array
var myArray = [1, 2, 3, 4, 5];
function revArray(arr) {
var nArrr = new Array();
for (var i = 0; i <= arr.length; i++) {
nArrr.push(arr[arr.length - i]);
console.log(nArrr[i]);
}
}
@edrohler
Copy link
Author

edrohler commented Mar 4, 2016

I had a job interview to reverse an array. This was my original answer but the interviewers added to it which made it incorrect and inefficient. But I just tested this and this and it is the most efficient way to do an array reversal without using array.reverse();

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