Palindrom Checker - feedback welcomed

Hello. I would welcome any feed back on palindrome checker project. It’s simple, but I’d would like to know if my solution would be acceptable in real work environment. Maybe the code is clean enough (like the function train xD) or maybe there is some rare example that would fail test. Thank you in advance for every advice.

Here’s my code:

function palindrome(str) {
    let temp = str.replace(/\W|_/g, "").toLowerCase();
    let reversed = temp.split("").reverse().join("");
    return temp === reversed;
}


I think there is one big change you can make that would simplify this greatly. What are the first two let statements doing? What type of value do they hold? How would you normally compare those types of values to see if they are equal?

1 Like

Omg. I’m so stupid :slight_smile: Overthinked this. Thank you. Updated the code in my opening post.

That’s definitely better, but I think you can be even more concise. The conditional expression in your if statement:

temp === reversed

returns either true or false, which is what you want to return from the function. In other words, you want to return the result of temp === reversed.

Ahh, I see you just updated your code to do this. Good job!

1 Like

Hi @Shan1 !

I wrapped your solution in spoiler tags for those who have not worked on the problem yet.

Keep up the good work!

1 Like

Good call. I totally forgot to mention this.