Created
September 20, 2017 20:13
-
-
Save SakoMe/1e79b9e2fb397eedab155147b92b1fd0 to your computer and use it in GitHub Desktop.
Reverse a string
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 reverseString(str) { | |
return str.split('').reverse().join('') | |
} | |
console.log(reverseString('Hello')) | |
// Recursion | |
function reverseString(str) { | |
return (str === '') ? '' : reverseString(str.substr(1)) + str.charAt(0); | |
} | |
reverseString("hello"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment