Skip to content

Instantly share code, notes, and snippets.

@pdewouters
Created April 24, 2015 09:50
Show Gist options
  • Save pdewouters/1f8f68759bad9116aba1 to your computer and use it in GitHub Desktop.
Save pdewouters/1f8f68759bad9116aba1 to your computer and use it in GitHub Desktop.
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