← Back to challenges

Recursion: Case and Index Inverter

JavaScriptHardrecursionstringsvalidation

Instructions

Write a recursive function that takes a string input and returns the string in a reversed case and order.

Examples

invert("dLROW YM sI HsEt") ➞ "TeSh iS my worlD"

invert("ytInIUgAsnOc") ➞ "CoNSaGuiNiTY"

invert("step on NO PETS") ➞ "step on NO PETS"

invert("XeLPMoC YTiReTXeD") ➞ "dExtErIty cOmplEx"

Notes

  • No empty strings and will not contain special characters or punctuation.
  • You are expected to solve this challenge via recursion.
  • An iterative version of this challenge can be found via this link.
  • A collection of challenges in recursion can be found via this link.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.