Freecodecamp: Palindromes: ("1 eye for of 1 eye.") should return true

Created on 10 Dec 2015  路  6Comments  路  Source: freeCodeCamp/freeCodeCamp

Challenge Bonfire: Check for Palindromes has an issue.
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:44.0) Gecko/20100101 Firefox/44.0.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

function palindrome(str) {
  // Good luck!
  var p = str.replace(/\s|\d|[,!@#$%^&*()-:_.]/g, '').toLowerCase().split("").reverse("").join("");
  str= str.replace(/\s|\d|[,!@#$%^&*()-:_.]/g,"").toLowerCase();
  if(str === p){
    return true;
  } else{
    return false;
  }
//  return true;
}



palindrome("race car");

Most helpful comment

@ubcgga For the bonfire, delete punctuation, spaces and symbols, but keep numerals.

All 6 comments

Why do you consider '1 eye for of 1 eye' to be a palindrome?
It is not a palindrome, so it should return false.

@ubcgga For the bonfire, delete punctuation, spaces and symbols, but keep numerals.

Closing as this is not an issue with the site.

I made the same mistake @ubcgga!

Numbers like '1234567890' aren't to be removed when comparing palindromes.

_removed solution by mod_

Everyone who is misguided please consider that they asked to remove all the non-alphanumeric characters. Do not remove numbers because its a part of the alphanumeric keyboard!
Try this:
str = str.replace(/[\W\s\_]/gi,"");

function palindrome(str) {
str = str.toLowerCase().replace(/[Ws_]/gi,"");
return str === str.split("").reverse().join("");
}

palindrome("eye");

Was this page helpful?
0 / 5 - 0 ratings

Related issues

itsmikewest picture itsmikewest  路  3Comments

MelissaManning picture MelissaManning  路  3Comments

DaphnisM picture DaphnisM  路  3Comments

bagrounds picture bagrounds  路  3Comments

trashtalka3000 picture trashtalka3000  路  3Comments