Is there any way I can improve this code? :
// first filter out all non alphanumeric characters in the string
// then convert it to lowercase
// split the string
// reverse the string
// /[1]$/
// /[\w\s]/
function palindrome(str) {
const regex = /[\W_]/g
str = str.replace(regex, “”).toLowerCase()
const reversedStr = str.split(“”).reverse().join(“”)
return (str === reversedStr ? true : false)
}
console.log(palindrome(“0_0 (: /-\ 0-0”));
-
\w*\s* ↩︎