Created
February 11, 2016 16:22
-
-
Save NEbere/7ac858d8e9271105ffba to your computer and use it in GitHub Desktop.
checks for palindromes. returns true if given string is a palindrome and false if not
This file contains 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) { | |
var newStr = str.replace(/[^a-zA-Z 0-9]+| /g,'').toLowerCase(); | |
var newStr1 = newStr.split('').reverse().join(''); | |
if(newStr == newStr1){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
//calling the function. returns true | |
palindrome("eye"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment