Skip to content

Instantly share code, notes, and snippets.

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

  • Save tianmingzuo/745de57687a2541e9bd80ea7c1c6dd83 to your computer and use it in GitHub Desktop.

Select an option

Save tianmingzuo/745de57687a2541e9bd80ea7c1c6dd83 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) {
// Good luck!
let newStr = str.replace(/\W|_/g, '');
newStr = newStr.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");
@Heks0
Copy link

Heks0 commented Mar 6, 2023

Thanks

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