-
-
Save anonymous/48fa4cb9d1aea5cd71fb6437c6ab7f76 to your computer and use it in GitHub Desktop.
palindrome testing
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) { | |
/* 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