Answer the question
In order to leave comments, you need to log in
How to reverse a string with recursion?
How to reverse a string recursively using the length of the string and getting a substring?
I do not understand how to set a condition for recursion?
const reverse = (str) => {
let res = '';
const index = str.length-1;
if (index === 0 || index === 1) return str;
else {
res += iter(str, index)
}
};
const iter = (str, index) => {
if (index !== 0) return iter(str, index-1);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question