2

I have an array with two thousand single-character strings.

["f", "j", "w", "/", ":", "u", "9", etc...]

I can reverse this with array.reverse(). But two thousand things being reversed takes at least 5-7 seconds on my VPS. How can I make this task more efficient?

4
  • 2
    The question is; What is this? What are trying to do? Commented Sep 8, 2018 at 20:22
  • @LucaKiebel its in the title? Commented Sep 8, 2018 at 20:25
  • 1
    @apxx He wants to know why you want to reverse the array! Commented Sep 8, 2018 at 20:26
  • 2 thousand is not very big. My library goodcore uses one of the temp swap algorithms in the link and I can easily handle much much larger arrays than that. Commented Sep 8, 2018 at 21:27

1 Answer 1

7

Could you just read the array in reverse instead of reversing it? You could also create a wrapper class around Array e.g., ReversibleArray which uses the same backing array instance but could be read forwards or backwards depending on some property like readInReverse: true|false on instances of that class.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.