Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Reverse a String Recursively

A Closer Look at Functionsmedium

Course · Section 10: A Closer Look at Functions · Lecture 137: First-Class and Higher-Order Functions

Implement `reverseStr(s)` returning the reverse of `s` using recursion.

Sample tests

Input: reverseStr("abc")
Output: "cba"
Input: reverseStr("")
Output: ""

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Forgetting the base case for empty or single-character strings.

Learning resources

  • MDN: Recursion
Approach & explanation (try first)

Reversing the rest of the string and appending the first character builds the full reversal.

Loading...
⌘/Ctrl + Enter

Run your code to see results.