# Check for Palindromes condition issue

Check for Palindromes condition issue
0

#1

Tell us what’s happening:
I have been able to satisfy all conditions save 1 i.e. “0_0 (: /-\ 0-0”. According to the exercise, this should return true but I think it should return false since on reversing it, it becomes “0-0 ): -/ 0_0”. Can someone help me with this?

``````var arr = [];
var str1 = "";
// var test = /[' ']/
function palindrome(str) {
// Good luck!
str = str.toLowerCase();
str = str.replace(/[' '|_|,|.]/gi, '');
arr = str;
arr = arr.split('');
arr.reverse();
str1 = arr.join('');
if (str1 == str)
return true;
else
return false;
}

palindrome("0_0 (: /-\ :) 0-0");
``````

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

#2

The input “0_0 (: /-\ 0-0” should return true because we need to only take the numbers and characters so the inputed string would become "0000"
which is a pallindrome.

Try
str=str.replace(/[^a-zA-Z0-9]/g, ‘’); //will take only numbers and alphabets and ignore others.
str = str.replace(/[’ '|_|,|.]/gi, ‘’);

#3

It worked. That was pretty neat. So I guess that caret stands for not(!) as in anything apart from a-z or A-Z or 0-9 would be ignored? But shouldn’t that caret be outside the bracket ^[a-zA-Z0-9] to include all 3 regexes or that’s just the way it is written[^a-zA-Z0-9]?

#4

[abc] -This is used for finding any character between the brackets and
[^abc] -This is for finding any character NOT between the brackets

These are syntaxes and there must be some reason for using it that way, may be it was used to not make it confusing with below expression but am not sure

^abc - Matches any string with abc at the beginning of it.