Skip to content

Instantly share code, notes, and snippets.

@NEbere
Created February 11, 2016 16:22
Show Gist options
  • Save NEbere/7ac858d8e9271105ffba to your computer and use it in GitHub Desktop.
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
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