Check for Palindromes ,"i think 1 eye fo r 1 eye " should return true

Tell us what’s happening: why this test case is not working :
palindrome(“1 eye for of 1 eye.”) should return false. I think its should return true

Your code so far

  var reverse = '';
  for(var i=0;i<str.length;i++){
    reverse = str[i] + reverse;
  return reverse;
function palindrome(str) {
  var list =  str.replace(/[^a-zA-Z]/g,"");
  list = list.toLowerCase();
  // Good luck!
  var reverse_list = reverse(list);
  if(list == reverse_list)
    return true;
    return false;

palindrome(" eye for of  eye.");

Your browser information:

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

Link to the challenge:

1 Like

Code to the test cases, not your own opinions as to what the test cases should be. That way, you’ll pass the challenges.

1 Like

@siddharth002 Why do you believe it should be considered a palindrome?

If you revert

1 eye for 1 eye
eye 1 rof eye 1

which is pretty different! :smile:

in the problem we have to first remove white space and special characters.
so our input string will looks like this : “eyeforofeye”;
and i think when u reverse it for checking pallindrom its gets= “eyeforofeye”;

since both strings are same, so its pallindrom?

You are removing white space and special characters, not numbers


@DanCouper was faster than me, you should leave digits in place. With that, it’s not a palindrome.

@lionel-rowe mmh I would not say “code to the test cases” unless somehow it’s defined and can be demonstrated that the test cases are covering the whole spectrum of possible instances, including both the standard and the corner cases.

At the contrary, I’d say that the challenge specification was clear enough, so follow it :slight_smile:

Fair point — I misspoke. What I should have said is “code to the spec”, rather than the test cases per se.

1 Like