Palindrome Checker [Bug

Tell us what’s happening:
Hey Guys! Thanks for checking in; I’m not sure why this doesn’t pass all the test in the FCC editor, yet it passes all tests in any other editor I’ve used. Any ideas?

Your code so far

function palindrome(str) {
  var newStr = str.toLowerCase().replace(/[\W+_]/g, '');
  let firstHalf;
  let secondHalf;
    const arr = newStr.split('');

    if(arr.length % 2==0){
     firstHalf = arr.slice(0, arr.length / 2);
     secondHalf = arr.slice((arr.length / 2), arr.length);
       firstHalf = arr.slice(0, arr.length / 2);
      secondHalf = arr.slice((arr.length / 2) + 1, arr.length);
   let result = () => firstHalf.reverse().join('') == secondHalf.join('');
    return result();  


palindrome("A man, a plan, a canal. Panama");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:

Don’t do console.log(result()). You’ll end up calling the function twice, which will not give the answer you’re expecting.


Wow, I’m deep in the rabbit hole. I use that for debugging but I generally remove all of them when I finish, but I guess I forgot. Rookie mistake! Thanks a lot :grinning:

1 Like