Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • 7
    Please explain what your code is doing. Commented Jul 26, 2016 at 22:53
  • 1
    Welcome to Stack Overflow! While this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, as this reduces the readability of both the code and the explanations! Commented Jul 27, 2016 at 1:10
  • 8
    Actually pretty neat idea. Javascript reverse()does what you would expect and the last item becomes the first which you can address by [0]. It's a native function available in all browsers so speed shouldn't be an issue here. Caveat: developer.mozilla.org/en/docs/Web/JavaScript/Reference/… says it's mutating the Array. So further accessing the reversed Array might be not what you expected! Commented Sep 16, 2016 at 8:57
  • 28
    Besides changing the array, this will also be extremely slow. Commented Sep 26, 2016 at 1:46
  • 5
    @svarog That only adds onto the time-complexity of the answer. Unnecessarily slow. Commented Jan 20, 2017 at 15:22