Palindrome (flawed)

// My code can detect whether a str is not a palindrome but cant decipher palindromes. Any hints would be appreciated.
function palindrome(str) {
 let adjStr = str.toLowerCase().replace(/[^a-z0-9]/g, "");
 for(let i=0;i<adjStr.length; i++) {
    if(adjStr[i] != adjStr.length-[i]){
      return false;
  }else{
    return true;
  }
}
}

palindrome(“eye”);

1 Like

Please put the link to the challenge back. That makes it easier for people to help you.

What does this part do?

It flips the chronology of the loop ( for idi, i = 1, d = 2, i = 3) becomes i (prev representing 3 = 1)

That’s what you intend for it to do, but what does that syntax literally mean?

the funny thing, but the expression will give the expected result.

No… It won’t give the desired result

5 - [2] // 3
i mean that

Right, but that’s not the entire purpose of that expression.

You’ve completely stumped me What does (adjStr[i] != adjStr.length-[i]) this actually do?

Yes. You’re right. I just looked at the piece of expression and missed the point.

This is a letter in the string, right?

Is this a letter from the string?

1 Like

Ive tried invalidating my presupposition but I can’t find anything to ```
var lastChar = myString[myString.length -1];

OK but now when I alter my code to become ```
if(adjStr[i]!=adjStr[adjStr.length-i])
         return false;

Im still left with errors

1 Like

Careful here. This is close, but you want to start at

1 Like
// Your a saint for walking me through this.
function palindrome(str) {
  
   let adjStr = str.toLowerCase().replace(/[^a-z0-9]/g, "");
   for(let i=0;i<adjStr.length; i++) {
     if(adjStr[adjStr.length + i] !=adjStr[adjStr.length-i]){
         return false;
     }
    else{
      return true;
    }
  
   }}
  

palindrome("eye");

But it now only picks up some of the palindromes

correction now i can find palindromes but anything that isnt a palindrome is left undiscovered

which letters are you comparing?
will that let you compare the first and the last one?

it seems to me you have undefined lots of time in there.

1 Like

gotcha another loop is required

no, it’s not, you need to fix the comparison

adjStr[adjStr.length + i] !=adjStr[adjStr.length-i]

what are the values in here for each value of i?

1 Like
function palindrome(str) {
  
    let adjStr = str.toLowerCase().replace(/[^a-z0-9]/g, "");
    for(let i = 0; i < adjStr.length; i++) {
      ***if(adjStr[i] !== adjStr[adjStr.length -1 - i]){***
***          return false;***
      }
     else{
       return true;
     }
   
    }}
   
 
 palindrome("eye");

// I’ve identified why my prev solution didnt work
//However, palindrome(“almostomla”)should returnfalse` . Is remaining a painful thorn in my side.