Created
October 14, 2019 01:55
-
-
Save tianmingzuo/9e280c426319eee45a92be7e327c0c33 to your computer and use it in GitHub Desktop.
Palindrome Checker: Return true if the given string is a palindrome. Otherwise, return false. A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing. Note You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the …
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
| function palindrome(str) { | |
| let newStr = str.replace(/\W/g, ''); | |
| newStr = newStr.replace('_', '').toLowerCase(); | |
| let revStr = newStr.split('').reverse().join(''); | |
| if(newStr === revStr){ | |
| return true; | |
| } | |
| return false; | |
| } | |
| //palindrome("eye"); | |
| //palindrome("0_0 (: /-\ :) 0-0"); | |
| //palindrome("five|\_/|four"); | |
| palindrome("A man, a plan, a canal. Panama"); |
MahdiRezaeiDev
commented
Oct 9, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment