Created
December 31, 2013 02:19
-
-
Save bresson/8191467 to your computer and use it in GitHub Desktop.
Javascript right to left string reversal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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