Write a recursive JS function to determine if a string is palindrome or not.
Return true if it is a palindrome, and false if it is not a palindrome.
I used regex to first get rid of the spaces and any puntuation.
For example :
Madam, I'm Adam - should return true, because it's the same backwards as forwards.
Answer in the comments.
var test = "Madam I'm Adam";
ReplyDeletevar paliChecker = function(str){
var paliCheck = [];
str = str.replace(/ |' |.|'?'|!/g, "").toLowerCase();
var length = str.length;
var num = 0;
function poop(){
if(paliCheck.length === length){
return paliCheck.join("") === str;
}
num ++;
paliCheck.push(str[str.length - num]);
return poop();
}
return poop();
}
var maple = paliChecker(test);