Help needed regarding this problem's logic

Help needed regarding this problem's logic
0

#1

function palindrome(str) {
// Good luck!

str=str.toLowerCase();

var arr=str.split(’’);

arr=arr.filter(function(ch){
return /[a-z]/.test(ch);
});

arr=arr.reverse();

arr=arr.join(’’);

if(str===arr) return true;

else return false;

// return str.toLowerCase().split(’’).filter(function(ch){
// return /[a-z]/.test(ch);
// }).reverse().join()===str;
}

palindrome("_eye");

Can someone pls help me in finding the mistake in this approach?

Thanks in advance


#2

This:

’’

is not an empty string. Those are:

'' ""

#3
testVar = _eye
arr = eye
str = _eye

testVar = race car
arr = racecar
str = race car

testVar = A man, a plan, a canal. Panama
arr = amanaplanacanalpanama
str = a man, a plan, a canal. panama

get rid of space and symbol in your str


#4

Hi…yea…it’s already taken care of, using regexp…thanks


#5

Hi…we can use either single quotes or double quotes to store string…right?


#6

The answer to your question is Yes.