Tell us what’s happening:
Hey Guys! Thanks for checking in; I’m not sure why this doesn’t pass all the test in the FCC editor, yet it passes all tests in any other editor I’ve used. Any ideas?
Your code so far
function palindrome(str) {
var newStr = str.toLowerCase().replace(/[\W+_]/g, '');
let firstHalf;
let secondHalf;
const arr = newStr.split('');
if(arr.length % 2==0){
firstHalf = arr.slice(0, arr.length / 2);
secondHalf = arr.slice((arr.length / 2), arr.length);
}
else{
firstHalf = arr.slice(0, arr.length / 2);
secondHalf = arr.slice((arr.length / 2) + 1, arr.length);
}
let result = () => firstHalf.reverse().join('') == secondHalf.join('');
console.log(result());
return result();
}
palindrome("A man, a plan, a canal. Panama");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker