Skip to content

Instantly share code, notes, and snippets.

@bresson
Created December 31, 2013 02:19
Show Gist options
  • Save bresson/8191467 to your computer and use it in GitHub Desktop.
Save bresson/8191467 to your computer and use it in GitHub Desktop.
Javascript right to left string reversal
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
</body>
</html>
function reverse(str) {
if (str.length === 1) {
return str;
} else {
//var n = str.length - 1;
return str.substr(-1) + reverse(str.slice(0, str.length - 1));
}
}
console.log(reverse('tift'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment