Here is my code -
[code]
function palindrome(str) {
// Good luck!
var str1 = str.replace(/\W/g,’’);
var str2 = str1.toLowerCase();
var pal = true;
for(var i = 0; i < str2.length-1; i++){
var j = str2.length - i -1;
if(str2[i] != str2[j]){
pal = false;
}
}
return pal;
}
[/code]
Only the testcases - palindrome("_eye") and palindrome("0_0 (: /-\ :) 0-0") are not passing. I’m still trying to figure out what’s wrong with the code, any help is appreciated.
Thanks for the link!
So the problem basically is the regex i have given doesn’t detect underscore. I gave a separate replace statement for _ and completed.