Skip to content

Instantly share code, notes, and snippets.

@spcbfr
Created July 15, 2021 22:24
Show Gist options
  • Save spcbfr/6bff4aca9c9cdeb74876d58e9163ba63 to your computer and use it in GitHub Desktop.
Save spcbfr/6bff4aca9c9cdeb74876d58e9163ba63 to your computer and use it in GitHub Desktop.
function palindrome(str) {
/* steps:
remove punctuation, spaces symbols
turn everything into lowercase
check if string inverted === str
*/
let regexRemove = /[,.'"?!@#$%^&*()_-\s]/g
str = str.replace(regexRemove,"").toLowerCase()
// now we have a clean string
let newThing = []
for(let i = 0; i < str.length; i++){
newThing.unshift(str[i])
}
newThing = newThing.join("")
if(newThing === str) {
return true
}
return false
}
console.log(palindrome("beye"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment