Created
May 16, 2019 23:16
-
-
Save Lavrend/9684c439741efe90409b6f40c4916b2a to your computer and use it in GitHub Desktop.
Palindrome check
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 isPalindrome = (str = '') => { | |
const reg = /[^A-Za-z0-9]/g; | |
const baseStr = str.toLowerCase().replace(reg, ''); | |
const reverseStr = baseStr.split('').reverse().join(''); | |
return reverseStr === baseStr; | |
}; | |
// Test | |
isPalindrome("A man, a plan, a canal. Panama"); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment