Skip to content

Instantly share code, notes, and snippets.

/palindrome.js Secret
Created Aug 5, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.