Created
November 8, 2016 15:10
-
-
Save oliverjam/413c7d2826ced566369fc2d78150a103 to your computer and use it in GitHub Desktop.
EJ: C4 P2 created by oliverjam - https://repl.it/ESIN/1
This file contains hidden or 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(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