Skip to content

Instantly share code, notes, and snippets.

@Giagnus64
Created January 20, 2020 18:28
Show Gist options
  • Select an option

  • Save Giagnus64/bf4a461342bcf147bdbba72c9bb633b2 to your computer and use it in GitHub Desktop.

Select an option

Save Giagnus64/bf4a461342bcf147bdbba72c9bb633b2 to your computer and use it in GitHub Desktop.
Reverse a string
function reverse(str){
// if we arrive at the final character of the string, return that character
if (str.length === 1) return str[0];
//otherwise return the last character of the string, plus the reverse function called on a sliced version of that string
return str[str.length - 1] + reverse(str.slice(0, str.length - 1))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment