Skip to content

Instantly share code, notes, and snippets.

@MohdSaifulM
Created November 30, 2022 17:06
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 MohdSaifulM/5e495aabf3ce201b7f36be0001a088df to your computer and use it in GitHub Desktop.
Save MohdSaifulM/5e495aabf3ce201b7f36be0001a088df to your computer and use it in GitHub Desktop.
Algorithms - Recursion
function reverse(str) {
// Base case
if (str.length === 0) return str;
// Recursive case (shift first letter to the end of string)
return reverse(str.slice(1)) + str[0];
}
reverse('awesome') // 'emosewa'
reverse('rithmschool') // 'loohcsmhtir'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment