Skip to content

Instantly share code, notes, and snippets.

/palindrome.js Secret

Created August 5, 2017 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/48fa4cb9d1aea5cd71fb6437c6ab7f76 to your computer and use it in GitHub Desktop.
Save anonymous/48fa4cb9d1aea5cd71fb6437c6ab7f76 to your computer and use it in GitHub Desktop.
palindrome testing
function palindrome(str) {
/* Input: String under test
Tests the string only for Alphanumeric characters.
return: true if the string is a palindrome or false if not.
*/
function removeChars(str){
str = str.toLowerCase();
var matches = str.match(/[a-z0-9]+/g);
console.log(matches);
return (matches.join(""));
}
function isPal(newStr){
if (newStr.length <= 1) {
return true;
}else {
return ((newStr.endsWith(newStr[0])) && (isPal(newStr.substr(1,newStr.length -2))));
}
}
return isPal(removeChars(str));
}
console.log(palindrome("$eazyzae$"));
console.log(palindrome("eye"));
console.log(palindrome("EYE"));
console.log(palindrome("EYES"));
console.log(palindrome("A man, a plan, a canal. Panama"));
console.log(palindrome("1 eye for of 1 eye."));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment