Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function palindrome(str) {
str = str.replace(/\s/gi, ''); // replace empty spaces
str = str.replace(/\W/gi, ''); // replaces non-word characters
str = str.replace(/_/, ''); // replaces underscore symbol
str = str.toLowerCase(); // lowercases the string
var strReversed = str.split('').reverse().join(''); //reversed the string
return (str === strReversed) ? true : false; // returns false if the str =! strReversed
}
palindrome("0_0 (: /-\ :) 0-0");
@jamc92

This comment has been minimized.

Copy link
Owner Author

@jamc92 jamc92 commented Apr 3, 2016

  • palindrome("eye") should return a boolean.
  • palindrome("eye") should return true.
  • palindrome("race car") should return true.
  • palindrome("not a palindrome") should return false.
  • palindrome("A man, a plan, a canal. Panama") should return true.
  • palindrome("never odd or even") should return true.
  • palindrome("nope") should return false.
  • palindrome("almostomla") should return false.
  • palindrome("My age is 0, 0 si ega ym.") should return true.
  • palindrome("1 eye for of 1 eye.") should return false.
  • palindrome("0_0 (: /-\ :) 0-0") should return true.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment