Created
November 18, 2015 09:54
-
-
Save shayanahmed1993/428da4a4e8989ec32987 to your computer and use it in GitHub Desktop.
#JavaScript: 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. You'll need to remove punctuation and turn everything lower case in order to check for palindromes. We'll pass strings with varyi…
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! | |
/* remove special characters, spaces and make lowercase*/ | |
var removeChar = str.replace(/[^A-Z0-9]/ig, "").toLowerCase(); | |
/* reverse removeChar for comparison*/ | |
var checkPalindrome = removeChar.split('').reverse().join(''); | |
/* Check to see if str is a Palindrome*/ | |
if(removeChar === checkPalindrome){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
palindrome("eye"); |
read up about regular expression (regex)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this couldn't run