递归Palindrom既不返回true也不返回false

问题描述

我试图编写一个递归式的palindrom,尽管我在最后一次迭代时最终到达了真正的分支,但返回值仍然不确定。

因此,如果您在控制台中输入带有palindrom的功能。 rekurzivSzigoruPalindrom(“ radar”);

它将完美地遍历它,但是返回值是不确定的。 您能否在下面的代码中指出错误? 谢谢

function rekurzivSzigoruPalindrom(str,strLength = str.length) {
// debug eleje
console.log(strLength);
if (strLength > 1) {
console.log(str[str.length - strLength] + "  " +str[strLength-1] );
}
if(strLength == 1){
console.log(str[str.length-1]+ "   " +str[strLength-1]);
}
//debug vége
  if(typeof str == "string" || typeof str == "number"){
    if(typeof str == "number"){
       str = str.toString();
    }
  
    
    if(strLength > 1){
      if(str[str.length - strLength] == str[strLength-1]){
        //console.log(strLength);
        strLength--;
        
        rekurzivSzigoruPalindrom(str,strLength);
        }

    }
    else if(strLength == 1){
      if(str[str.length-1] == str[strLength-1]){
       console.log(strLength+"true");
        return true;
      }
      else{
        console.log(strLength+"false");
        return false;
        }    
        

      }

    }

    else {
      return false;

    }   
     
  }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)