Created
July 15, 2021 22:24
-
-
Save spcbfr/6bff4aca9c9cdeb74876d58e9163ba63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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