Created
October 14, 2019 01:59
-
-
Save tianmingzuo/745de57687a2541e9bd80ea7c1c6dd83 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) { | |
| // Good luck! | |
| let newStr = str.replace(/\W|_/g, ''); | |
| newStr = newStr.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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks