reverse method

String reverse()

Returns this with characters in reverse order.

Example:

'word'.reverse(); // 'drow'

WARNING: This is the naive-est possible implementation, relying on native string indexing. Therefore, this method is almost guaranteed to exhibit unexpected behavior for non-ASCII characters.

Implementation

String reverse() {
  final stringBuffer = StringBuffer();
  for (var i = length - 1; i >= 0; i--) {
    stringBuffer.write(this[i]);
  }
  return stringBuffer.toString();
}