Hello everyone, I have a question, but first I’ll explain the steps that I followed
1- i created a variable for the string without symbols, punctuations or white spaces.
2- i created another variable to find the reverse version of the string. To see if it will still look like the original version.
3- i used console.log() for both of the variables to see if I succeeded achieving the desired outcome. Which was to remove punc,symbols or white spaces. And to see if the string is a palindrome using reverse() method, which helps me to reverse the sorting order of the string. Both variables returned the same results.
4- I used console.log() method to add the test() method inside it, to check if the regex matches the string. The challenge requries me to return a boolean value. Test() method will return a boolean value.
My question is:
What’s wrong with my code? When I used console.log() to log both variables, the results of both were the exact same. Yet, when i use test method to see if /string2/ matches string1. I get false.
function palindrome(String) {
let string1 = String.replace(/[\p{P}]|\s/gu, "");
let string2 = string1.split("").reverse().join("");
console.log(string1);
console.log(string2);
console.log(/string2/i.test(string1));
}
palindrome("eye");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15
Challenge Information:
JavaScript Algorithms and Data Structures Projects - Palindrome Checker