Created
September 7, 2017 08:17
-
-
Save adyngom/490f5ea9d49501008a2ce5c8f3d424da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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