Problems with finding the median on: : Palindrome Checker

Tell us what’s happening:
So I am trying to sollut this one
But i am stuck onto line 12
how do i divine the median by 2 and then get the whole number?
Also the special character seems to be a problem I can only find how to omit them out with a backslash but not how to filter them out.

Here’s the logic i am using

Find out the lengtt of the string by counting each substring
Arrange your numbers in numerical order.
Count how many numbers you have.
If you have an odd number, divide
by 2 and round up to get the position of the median number.
now use the median as a turning point
and compare left to right

bob
count the letters/nums in the sub string
divine it in half

if the number of letters is 3 like with bob
then it uses the middel letter as a turning point
and compares the 1st b to the last one ignoring the middel
so if 1st set letters is equal to the 2nd one

Your code so far


function palindrome(str) {
var str = str.toUpperCase();
var str =  str.trim();
var str = str.RegExp('/d');
var len = str.length;
if (len % 2 == 0){

return false }
else (len % 2 != 0); {
return  median = len
}
median = median / 2 Math.ceil(len)
var a = str.slice(0 , median);
var b =  str.slice( median, -1);
if a == b;
return true
}



palindrome("eye");

Your browser information:

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

Challenge: Palindrome Checker

Link to the challenge:

1 Like

Also is there a way to

var str =  str.trim();
var str = str.RegExp('/d');
var len = str.length;```
make this one more neater and do it in 1 line it seems like a long repeat
1 Like

Are you sure this is the cleanest logic? How about remove spaces and special characters (maybe string.replace() with a non-alphanumeric regex?), make a copy of that string and reverse it, and compare them?

1 Like

Not at all but, since I still don’t understand much of it this was the best thing I could come up with.

How about remove spaces and special characters (maybe string.replace() with a non-alphanumeric regex?), make a copy of that string and reverse it, and compare them?

Yes that is a very good idea thank you I am going to try will keep this post up to date when I figured it out :3

1 Like