Tell us what’s happening:
Your code so far
function palindrome(str) {
//string interpolating uses special single quotes and ${variable}
console.log(`^\n : ${str}`);
//get rid of special characters
let s = str.replace(/[^a-zA-Z ]/g, "");
//remove spaces
s = s.replace(/\s/g, '');
//lowercase
let sl = s.toLowerCase();
console.log(` compare : ${sl}`);
//string to array
let a = sl.split("");
//reverse the array
let r = a.reverse();
//create a string from array using join()
let jstr = r.join("");
console.log(` Reverse : ${jstr}`);
if(jstr == sl ){
console.log(" : true")
return true;
}
else{
console.log(" : false")
return false;
}
}
palindrome("eye");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8
.
Link to the challenge:
https://www.freecodecamp.org/challenges/check-for-palindromes
One of the tests for Palindrome is :palindrome(“1 eye for of 1 eye.”) should return false.
once the '1’s are removed from the string it reads “eyeforofeye” which is a palindrome.
but the question indicates that it should not be a palindrome.