Challenge Bonfire: Check for Palindromes has an issue.
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:44.0) Gecko/20100101 Firefox/44.0
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
function palindrome(str) {
// Good luck!
var p = str.replace(/\s|\d|[,!@#$%^&*()-:_.]/g, '').toLowerCase().split("").reverse("").join("");
str= str.replace(/\s|\d|[,!@#$%^&*()-:_.]/g,"").toLowerCase();
if(str === p){
return true;
} else{
return false;
}
// return true;
}
palindrome("race car");
Why do you consider '1 eye for of 1 eye' to be a palindrome?
It is not a palindrome, so it should return false.
@ubcgga For the bonfire, delete punctuation, spaces and symbols, but keep numerals.
Closing as this is not an issue with the site.
I made the same mistake @ubcgga!
Numbers like '1234567890' aren't to be removed when comparing palindromes.
_removed solution by mod_
Everyone who is misguided please consider that they asked to remove all the non-alphanumeric characters. Do not remove numbers because its a part of the alphanumeric keyboard!
Try this:
str = str.replace(/[\W\s\_]/gi,"");
function palindrome(str) {
str = str.toLowerCase().replace(/[Ws_]/gi,"");
return str === str.split("").reverse().join("");
}
palindrome("eye");
Most helpful comment
@ubcgga For the bonfire, delete punctuation, spaces and symbols, but keep numerals.