Does JS allow you to treat strings as arrays? If so, this may be possible to implement faster by explicitly testing values through an incrementing (for ltrim) and decrementing (for rtrim) "for" loop. Then you don't have the overhead of compiling and running a regex each and every time you trim. Of course, JS may have optimized that enough that there won't be much speed difference. Still, for client-side scripting, speed is even more important: you want to present content in as method-transparent a manner as possible.
I've got good news, and I've got bad news: The universe is merely a figment of my imagination. Now are you ready for the bad news?
I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?