I can see the code you have written. But I don’t understand what you thing if (str) does. It doesn’t seem to be related to checking for a palindrome at all, so I’m trying to understand what you are thinking.
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
I would suggest you start by just telling us the steps you would take to determine if a string is a palindrome. Don’t even worry about writing any code yet. Just tell us in plain English what you would do to figure it out.
im sure u learn the RegExp section. use what u learned in that section. palindrome checker is checking the str arguments same or not with reversed str. try to using regexp section to fulfill this project
There are a lot of ways to code a solution for this problem. Your solution is fine, but you are introducing a loop, which is not necessary if you use a functional approach. For instance, it is possible to solve this problem with just one return statement. Granted, there are just a few methods being used in that return statement, but a lot of people would consider the fact that you didn’t need to add a loop worth it.
Personally, I would probably use two lines of code to solve this problem because you can remove some repetitive method calls by cleaning up the input string first. I would suggest you you try to solve this using a functional approach and see if you can get it down to two lines of code as well (or even one if you prefer).
Two lines would be a big change. I’ll have to take a look! (probably after I finish the rest of the projects first).
EDIT: By functional do you mean recursive? I definitely have a very limited grasp of recursion so far (used it successfully in one of the algos, but otherwise only in the actual lessons on it). If not, can you explain what functional means in this case? I did avoid modifying any passed values, which I thought was the definition. Thank you for the help!
This is another reason why many people would prefer a functional approach for this solution, because two lines of code is simpler. Also, using functional methods often leads to better readability because the method names usually tell you what the method is doing.