Skip to content

Instantly share code, notes, and snippets.

@tianmingzuo
Created October 14, 2019 01:55
Show Gist options
  • Select an option

  • Save tianmingzuo/9e280c426319eee45a92be7e327c0c33 to your computer and use it in GitHub Desktop.

Select an option

Save tianmingzuo/9e280c426319eee45a92be7e327c0c33 to your computer and use it in GitHub Desktop.
Palindrome Checker: Return true if the given string is a palindrome. Otherwise, return false. A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing. Note You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the …
function palindrome(str) {
let newStr = str.replace(/\W/g, '');
newStr = newStr.replace('_', '').toLowerCase();
let revStr = newStr.split('').reverse().join('');
if(newStr === revStr){
return true;
}
return false;
}
//palindrome("eye");
//palindrome("0_0 (: /-\ :) 0-0");
//palindrome("five|\_/|four");
palindrome("A man, a plan, a canal. Panama");
@MahdiRezaeiDev
Copy link

function palindrome(str) {
  str = str.replace(/[^a-zA-Z0-9]/g, '');
  return str.toLowerCase() == str.toLowerCase().split('').reverse().join('');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment