Skip to content

Instantly share code, notes, and snippets.

@SakoMe
Created September 20, 2017 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SakoMe/1e79b9e2fb397eedab155147b92b1fd0 to your computer and use it in GitHub Desktop.
Save SakoMe/1e79b9e2fb397eedab155147b92b1fd0 to your computer and use it in GitHub Desktop.
Reverse a string
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