Programming-Idioms

Implementation
JS

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
String t = new StringBuilder(s).reverse().toString();
runes := []rune(s)
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
   runes[i], runes[j] = runes[j], runes[i]
}
t := string(runes)
t = s.decode('utf8')[::-1].encode('utf8')
var t = new String.fromCharCodes(s.runes.toList().reversed);
t = s.reverse
let t = s.chars().rev().collect::<String>();
for ($i=0;$i<mb_strlen($s);$i++) {
    $characters[] = mb_substr($s, $i, 1, 'UTF-8');
}

$characters = array_reverse($characters);
$t = implode($characters);
import std.range, std.array;
auto t = s.retro.array;
Function ReverseString(const AText: string): string;
var
    i,j:longint;
begin
  setlength(result,length(atext));
  i:=1; j:=length(atext);
  while (i<=j) do
    begin
      result[i]:=atext[j-i+1];
      inc(i);
    end;
end;
t = reverse s :: String
t = String.reverse(s)
T = lists:reverse(S)
char[] charArray = s.ToCharArray();
Array.Reverse(charArray);
string t = new string(charArray);
s.reverse
function utf8.reverse(s)
	local r = ""
	for p,c in utf8.codes(s) do
		r = utf8.char(c)..r
	end
	return r
end

t = utf8.reverse(s)
var t = s.split('').reversed.join();

function reverse(const str: string): string;
var
  i, j: Integer;
begin
  j := length(str);
  setlength(reverse, j);
  for i := 1 to j do
    reverse[i] := str[j - i + 1];
end;
my $s = 'cafe' . "\N{COMBINING ACUTE ACCENT}";
my $t = join '', reverse $s =~ /\X/g;
t = s[::-1]
(reverse s)
std::string s("Example");
std::string t;
std::copy(s.crbegin(), s.crend(), std::back_inserter(t));
#include <stdlib.h>
#include <string.h>
char *strrev(char *s)
{
	size_t len = strlen(s);
	char *rev = malloc(len + 1);

	if (rev) {
		char *p_s = s + len - 1;
		char *p_r = rev;

		for (; len > 0; len--)
			*p_r++ = *p_s--;
		*p_r = '\0';
	}
	return rev;
}
val t = s.reversed()
(let [s "hello"
      t (apply str (reverse s))]
  t)
  character(len=:), allocatable :: t
  integer :: i, n

  allocate (t, mold=s)
  n = len(s)
  do i = 0, n - 1
     t(n-i : n-i) = s(i+1 : i+1)
  end do
IDENTIFICATION DIVISION.
PROGRAM-ID. reverse string.
PROCEDURE DIVISION.
    MOVE FUNCTION REVERSE(s) TO t
STOP RUN.
Dim string_t = StrReverse(string_s)
let t: String = s.chars().rev().collect();