How can I find all the substrings in any given string using a recursive function? I know how to do it using 2 for loops, but I don't know how to do it using recursion. Every substring needs to be checked for whether it's a palindrome. Here is my non iterative solution.
console.log(palindromeIterative("madam"));
function palindromeIterative(word) {
let noOfP = 0;
for (let i = 0; i < word.length; i++) {
for (let j = i + 1; j <= word.length; j++) {
noOfP = palindromeIterativeHelper(word.substring(i, j), noOfP);
}
}
return noOfP;
}
function palindromeIterativeHelper(word, noOfP) {
if (word === word.split("").reverse().join("") && word.length > 1) {
console.log(word);
noOfP++;
}
return noOfP;
}