Last active
April 9, 2021 23:15
-
-
Save winni4eva/798556602dcc23cc185bc2cf3c29a286 to your computer and use it in GitHub Desktop.
Validating palindromes
This file contains hidden or 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
const palindrome = (text) => { | |
const regex = /[\W_]/g; | |
const textWithOutUnWantedXters = text.toLowerCase().replace(regex, ''); | |
const reversedText = textWithOutUnWantedXters.split('').reverse().join(''); | |
return reversedText === textWithOutUnWantedXters; | |
} | |
const answer = palindrome('civic'); | |
console.log('IS PALINDROME ', answer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment