Skip to content

Instantly share code, notes, and snippets.

@okovalov
Created February 25, 2019 02:26
Show Gist options
  • Save okovalov/4e21b9c2fbdb66e590f4094eb7b3e14b to your computer and use it in GitHub Desktop.
Save okovalov/4e21b9c2fbdb66e590f4094eb7b3e14b to your computer and use it in GitHub Desktop.
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