8000 Fix palindromes false positive test by Mclilzee · Pull Request #227 · TheOdinProject/javascript-exercises · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@Mclilzee
Copy link
Member
@Mclilzee Mclilzee commented Feb 8, 2022

As all palindromes have the exact same first and last letter, people only had to test for first and last letter equallity, and the only test where it should return false, it has the first and last letters being different. to pass the whole test people only had to test for first and last letter weither they are equal or not, which make mistakes like this pass the test :

const palindromes = function (input) {
  let
F440
 str = input.replace(/[^0-9a-z]/gi, "").toLowerCase();
  for (var i in str) {
    if (str[i] != str[str.length-1-i]) {
      return false;
    }
    return true;
  }
};

this mistake happens to a lot of people, where they return true inside rather than outside the loop. I myself did this mistake many times.

My change will make sure that the first and last letter of a none-palindrome sentence the same, which returns true if people only tested first and last letter. passing the tests now require people to do the palindrome test properly.

Copy link
@OoChip OoChip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look ok

expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe(true);
});
test.skip('doesn\'t just always return true', () => {
expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look ok

Copy link
Member
@xandora xandora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, change looks good to me.

@xandora xandora merged commit 2f9f431 into TheOdinProject:main Feb 12, 2022
d2038 pushed a commit to d2038/javascript-exercises that referenced this pull request May 22, 2024
Oussama5379 added a commit to Oussama5379/javascript-exercises that referenced this pull request Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0