Palindrome Checker answer

I have figured out the solution to this problem but I was wondering if I can make it more efficient.

How could I change the regex in split so that I do not need to add the filter?

Thanks in advance

function palindrome(str) {
str = str.toLowerCase().split(/(?=\w)|\W/)
str = str.filter(element => {
  if (element === '-' || element === '' || element === '_') {
    return false
  return true

for (let i=0; i<str.length; i++) {
  if (str[i] !== str[str.length-1-i]) {
    return false
return true;

  **Your browser information:**

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

Challenge: Palindrome Checker

Link to the challenge:

I would concentrate on the note in the instructions:

Note: You’ll need to remove all non-alphanumeric characters

Reword that as “remove anything BUT alphanumeric characters.” You might consider doing this first before splitting.

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