Palindrome Checker.....Someone please be my code checker

Tell us what’s happening:
why is the front incrementor and back decrementor used twice in loop. Won’t it skip one string character to compare ?
Your code so far


    //this solution performs at minimum 7x better, at maximum infinitely better.
    //read the explanation for the reason why. I just failed this in an interview.
    function palindrome(str) {
      //assign a front and a back pointer
      let front = 0
      let back = str.length - 1

      //back and front pointers won't always meet in the middle, so use (back > front)
      while (back > front) {
        //increments front pointer if current character doesn't meet criteria
        if ( str[front].match(/[\W_]/) ) {
          front++
          continue
        }
        //decrements back pointer if current character doesn't meet criteria
        if ( str[back].match(/[\W_]/) ) {
          back--
          continue
        }
        //finally does the comparison on the current character
        if ( str[front].toLowerCase() !== str[back].toLowerCase() ){ 
          return false
        }
        front++
        back--
      
      }
      return true;
    }
console.log(palindrome("civic"));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker/

They are not just used twice, this is executed if the current character is not a letter or number, example taco cat - if there was the comparison between a space and a character then the function would say that it is not a palindrome, with that if statement then the space is ignored and next character is checked

There is to consider that this code will not work if there are two or more consecutive characters that are not a letter or a number as that code will work with just one not letter or number character to avoid

1 Like

Yeah, it took some time but i figured it…Thanks.
got confused after seeing that at first…