Created
February 25, 2019 02:26
-
-
Save okovalov/4e21b9c2fbdb66e590f4094eb7b3e14b to your computer and use it in GitHub Desktop.
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
const reverseArrayInPlace = arr => { | |
for(let i = 0; i < (arr.length / 2)+1; i++) { | |
const first = arr.shift() | |
arr.splice(arr.length - i, 0, first) | |
} | |
return arr | |
} | |
const arr = ['a', 'b', 'c', 'd', 'e'] | |
const reversed = reverseArrayInPlace([...arr]) | |
console.log(`reverse of '${arr}' is '${reversed}'`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment