hey all,
Any help here would be appreciated, not sure what is off here…
function palindrome(str) {
var cleanstring=str.replace(/[\W_]/g,'').toLowerCase();
var splitreverse=cleanstring.split('').reverse();
var joined=splitreverse.join('');
if (splitreverse==joined){
return true;
}
else {
return false;
}
}
palindrome("eye");
your splitreverse is an array and your joined is a string. do some console logs and you will find out what is wrong
1 Like
Really helpful, thank you.
Actually you were also comparing the new string with the new string.
`function palindrome(str) {
var cleanstring = str.replace(/[\W_]/g,’’).toLowerCase();
var newString = cleanstring.split(’’).reverse().join(’’);
if (cleanstring == newString){
return true;
}
else {
return false;
}
}
The general idea and the regExp was correct.Just some minor issues all and all
Pasted the code as you were really close so don’t feel like you are cheating or something.
1 Like