Skip to content

Instantly share code, notes, and snippets.

@adyngom
Created September 7, 2017 08:17
Show Gist options
  • Save adyngom/490f5ea9d49501008a2ce5c8f3d424da to your computer and use it in GitHub Desktop.
Save adyngom/490f5ea9d49501008a2ce5c8f3d424da to your computer and use it in GitHub Desktop.
String.prototype.isPalindrome = function() {
let specialChars = /[`~!@#$%^&*()_|+\-=?;’—:'",.<>\{\}\[\]\\\/]/gi;
let prepped = this.replace(specialChars, '').replace(/\s/g, '').toLowerCase();
return ( prepped === prepped.split('').reverse().join('') )
};
console.log("Matam", "Matam".isPalindrome()); // true
console.log("racecar", "racecar".isPalindrome()); // true
console.log("race car", "race car".isPalindrome()); // true
let longPal = 'Are we not pure? "No, sir!" Panama’s moody Noriega brags. "It is garbage!" Irony dooms a man—a prisoner up to new era.';
console.log(longPal.isPalindrome());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment