JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Tell us what’s happening:
I’m trying to figure out what I am doing wrong here. Trying to figure out how to do the " palindrome("1 eye for of 1 eye.") should return false ." bit, can anyone help me out here?

Your code so far

function palindrome(str) {

  const arr = str.match(/[a-z]/gi)

  if (arr === null) {
    return true;
  } 

  str = arr.join("").toLowerCase()
  const rev_str = arr.reverse().join("").toLowerCase()
  
  if(str === rev_str) {
    return true;
  }

  return false;
}

palindrome("eye");

Your browser information:

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

Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Link to the challenge:

Note: You’ll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.

Alphanumeric is letters and numbers

Ok, can you give me an example for a code like that?

your question is vague. What do you mean by “example of a code”?

If you mean you would like to know how to use regex patterns, you can revise this either on fCC in the javascript curriculum. oryou can also google “js regex cheat sheet” and get a list of different patterns and their meanings that you can try to apply

What I was trying to ask is for an example for the code to remove all non-alphanumeric characters, and to complete the " palindrome("1 eye for of 1 eye.") should return false ." requirement.

My suggestion is to take the information presented to you so far and try again.
If you cannot figure it out you can always ask for more help.

I’m trying to figure it out, but I’m not sure how to fix the code to complete the “palindrome("1 eye for of 1 eye.") should return false .” requirement.

This is a certification project. We cannot give you the code to solve the project.


Like I said, alphanumeric means letters and numbers. Right now you are only matching lower case letters with your regex.

There is a previous challenge on match numbers and letters.

Alright. Understandable…

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.