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?

APixel Visuals
  • 1,508
  • 4
  • 20
  • 38

1 Answers1

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.

johnheroy
  • 416
  • 2
  • 7