Skip to content

Instantly share code, notes, and snippets.

@winni4eva
Last active April 9, 2021 23:15
Show Gist options
  • Save winni4eva/798556602dcc23cc185bc2cf3c29a286 to your computer and use it in GitHub Desktop.
Save winni4eva/798556602dcc23cc185bc2cf3c29a286 to your computer and use it in GitHub Desktop.
Validating palindromes
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