Skip to content

Instantly share code, notes, and snippets.

@vldvel
Last active August 22, 2020 14:26
Show Gist options
  • Save vldvel/711baf4f7f9175550ce21eddbded9cae to your computer and use it in GitHub Desktop.
Save vldvel/711baf4f7f9175550ce21eddbded9cae to your computer and use it in GitHub Desktop.
const string1 = 'level';
const string2 = 'Le, vel.';
const isPalindrome = stringToTest => {
const stringTransformed = stringToTest
.replace(/[^\w]/gi, '') // replace all non-letter characters
.toLowerCase(); // make all characters lower cased
return stringTransformed === stringTransformed.split('').reverse().join('');
}
isPalindrome(string1); // true
isPalindrome(string2); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment