Created
March 4, 2016 21:03
-
-
Save edrohler/276180eae493f41fbff3 to your computer and use it in GitHub Desktop.
Reverse an Array
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
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]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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();