Reverse by hand
Inputs
text is 0 to 20 lowercase letters (a to z).
Your tasks
- Create an empty string
result. - Use a loop over
text. Put each character at the front ofresult, ahead of what is already there. - Complete
reverseTextso it returnsresult. Return it, do not print it.
Example
With text = "stressed", reverseText returns "desserts".
Rules
- Do not use a built-in reverse.
Test data
TEST DATA 1: text is "stressed"
TEST DATA 2: text is ""
Practice focus
Text is just a list of characters, so everything you know about lists applies. String problems in interviews are array problems with letters.