Skip to content

Instantly share code, notes, and snippets.

@sethschori
Forked from anonymous/Reverse String (3.3).js
Created July 31, 2016 19:47
Show Gist options
  • Save sethschori/ea31e3581580d076c018f9f1d9b78cb0 to your computer and use it in GitHub Desktop.
Save sethschori/ea31e3581580d076c018f9f1d9b78cb0 to your computer and use it in GitHub Desktop.
https://repl.it/CU9g/231 created by sethopia
/*
REVERSE STRING
Create a function that takes a string of any length as input and returns that string reversed.
Use recursion ;)
*/
function reverseString(str){
var n = str.length-1;
if(str.length < 1) return str;
return str.charAt(n) + reverseString(str.slice(0,n))
}
console.log(reverseString("Hello"));
Native Browser JavaScript
>>> olleH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment