|
|
|
|
|
by morelisp
1464 days ago
|
|
Why do you want a string reverse? - Do you want to reverse bytes, or codepoints? - Do you want to reveres codepoints, or grapheme clusters? - Do you really want to reverse grapheme clusters, or do you want to reverse some grapheme clusters while leaving e.g. sequences of control characters in the same order? - Do you really want to reify any of this rather than iterate backwards in the existing memory? |
|
C++: reverse(str.begin(), str.end());
Dart: str.split('').reversed.join();
Java: new StringBuilder().append(str).reverse().toString();
JavaScript: str.split('').reverse().join('');
PHP: strrev($str)
Python: ".join(reversed(str))
Rust: str.chars().rev().collect()