JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Tell us what’s happening:
I’m trying to solve this using Stack DS but I’m getting an error.
palindrome(“0_0 (: /-\ :slight_smile: 0-0”) should return true.
Can someone tell me how to fix my code?

function palindrome(str) {
const regex = new RegExp("[^a-zA-Z0-9\s-]", "g");
let word = str.replace(regex, "").toLowerCase();
let rword = "";
var letters = [];
for (var i = 0; i < word.length; i++) {

// pop off the stack in reverse order
for (var i = 0; i < word.length; i++) {
  rword += letters.pop();

if (rword === word) {
  return true;
else {
  return false;
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Link to the challenge:

Try to log what is in this variable after you use the regex to clean it up. Is it 0000?

No, it’s eye.

I mean you should add a console.log in the function….

Right now you are not logging inside the function.

You mean after line 3?
I tried console.log(word); there and it showed eye in the console.

Yes please.

Then you need to modify the test line(the last line) to give the string that is failing the fCC test…


palindrome(“0_0 (: /-\ :) 0-0”) 

It’s showing 00-0-0
The last line was palindrome(“0_0 (: /-\ :slight_smile: 0-0”);

So do you see the problem that you should fix now?

1 Like

Yeah, it worked after changing the regex and removing ‘-’

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.