Created
April 24, 2015 09:50
-
-
Save pdewouters/1f8f68759bad9116aba1 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
function reverseArray(items){ | |
var reversed = []; | |
for(var i=items.length;i>0;i--){ | |
reversed.push(items.pop()); | |
} | |
return reversed; | |
}; | |
console.log(reverseArray(["A","B","C"])); | |
function reverseArrayInPlace(arrayItems){ | |
for(var i=0;i<arrayItems.length;i++){ | |
var tmp = arrayItems[i]; | |
arrayItems[i] = arrayItems[arrayItems.length-(i+1)]; | |
arrayItems[arrayItems.length-(i+1)] = tmp; | |
} | |
}; | |
var arrayItems = [1,2,3,4,5,6,7]; | |
reverseArrayInPlace(arrayItems); | |
console.log(arrayItems); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment