DEV Community

Discussion on: Javascript Algorithms Challenges | Part 1

Collapse
 
zackarnault profile image
Zack Arnault

I just used str = str.toLowerCase().replace(/[a-zA-Z0-9]/ig, ""); to check for special characters and remove them. ^

Collapse
 
martinnrdstrm profile image
Martin Nordström

smart to use regex!!

Collapse
 
mahmoudmohasseb profile image
Mahmoud Mohasseb

function palindrome(str) {
//Transform input to lowercase alphanumeric only
let scrubbedString = str.toLowerCase().replace(/[^a-z0-9]/ig,'');

//Compare string to reversed string
if (scrubbedString === scrubbedString.split("").reverse().join("")){
return true;
}else {
return false;
}
}

palindrome("eye");