freeCodeCamp / freeCodeCamp

freeCodeCamp.org's open-source codebase and curriculum. Learn to code for free.
https://contribute.freecodecamp.org
BSD 3-Clause "New" or "Revised" License
404.57k stars 37.91k forks source link

Palindrome Bug: 0_0 (: /-\ :) 0-0 should NOT be true. Test is incorrect. #6058

Closed ghost closed 8 years ago

ghost commented 8 years ago

Challenge Bonfire: Check for Palindromes has an issue. User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0.

There's a clear bug with the very last Palindrome, as visually it's clear to see 0_0 (: /-\ :) 0-0 should NOT return true. The beginning shows "0_0 (", the end is ")0-0" while Visually, these appear SYMMETRICAL but it's not a palindrome.

Attached are two screenshots. The first one is the results of my test, and second is everything displayed in the console. I made it easy by identifying each string forward and backwards and you can see the last one clearly doesn't match, as I stated above. palindromeconsole palindrometest

My code:

function palindrome(str) {
  // Good luck!
  var checkArray = [];
  var word = str.toLowerCase();
  var newWord = word.replace(/[, .]/g, ""); 
  var reversed = newWord.split('').reverse().join('');
  console.log("Forward: " + newWord);
  console.log("Backwards: " + reversed);
  if(newWord === reversed) {
    return true;
  } 
    return false;
  }
SaintPeter commented 8 years ago

Nope, you're wrong. The test is correct.

The instructions are to remove all non-alphanumeric characters, IE: anything which is NOT 0-9 and a-z. If you do so, you'll end up with 0000, which is a palindrome, for the purposes of the exercise.

You should revisit your regex, which is not nearly expansive enough. I suggest http://regexr.com for reference and testing.

Finally - I encourage you to take your problems to the HelpBonfires channel where you will get excellent support by knowledgeable people who would have much more quickly told you the same thing.

Regards and Happy Coding!

ghost commented 8 years ago

Thanks! I must have missed the part about deleting ALL non-alphanumeric characters. I got it correct now. I still think the question is somewhat misleading though, you technically COULD check with characters in it and you would say "is this string the same backwards as it is forwards?" and the answer would have been NO for the last one.

It seems like cheating to remove symbols THEN check. My impression was that a palindrome was what I just described, the same in both directions, WITHOUT removing anything.

Weird, but I understand your point too, it's a matter of following the instructions.