Skip to content

Instantly share code, notes, and snippets.

@oliverjam
Created November 8, 2016 15:10
Show Gist options
  • Save oliverjam/413c7d2826ced566369fc2d78150a103 to your computer and use it in GitHub Desktop.
Save oliverjam/413c7d2826ced566369fc2d78150a103 to your computer and use it in GitHub Desktop.
EJ: C4 P2 created by oliverjam - https://repl.it/ESIN/1
function reverseArray(array) {
let result = [];
for (let i = array.length - 1; i >= 0; i--) {
result.push(array[i]);
}
return result;
}
function reverseArrayInPlace(array) {
for (let i = 0; i < Math.floor(array.length / 2); i++) {
let temporary = array[i];
array[i] = array[array.length - 1 - i];
array[array.length - 1 - i] = temporary;
}
return array;
}
console.log(reverseArray(["A", "B", "C"]));
const arrayValue = [1, 2, 3, 4, 5, 6, 100];
reverseArrayInPlace(arrayValue);
console.log(arrayValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment