Check for Palindromes Bug?

Tell us what’s happening:

Your code so far

function palindrome(str) {
  // Good luck!
  str = str.replace(/[\W_\0-9]/gi, '');
  str = str.toLowerCase();
  
  if (str.length == 1 || str.length == 0) {
    return true;
  }
  
  var odd = str.length % 2;
  var rle = str.length - 1;
  var itr = ((str.length - odd) / 2);
  
  for (var i = 0; i < itr; i++) {
    if (str[rle - i] != str[i]) {
      return false;
    }
  }
  
  
  return true;
}



palindrome("eye");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:55.0) Gecko/20100101 Firefox/55.0.

Link to the challenge:

Hi, I have a problem with this challenge. I can’t past trough it because in result I have an error: palindrome(“1 eye for of 1 eye.”) should return false. I think it should return true. Maybe I don’t get it. Is this a bug? eyeforofeye is not a palindrome?

It should return false because when you strip off non-alphanumeric chars from that string, you’ll get '1eyeforof1eye', which isn’t a palindrome.

1 Like

Ok, I missed that I have to leave numbers. Poor reading skills I guess. Thx for help.