UNPKG

swg01-palindrome

Version:
41 lines (31 loc) 904 B
module.exports = Phrase; // Adds revers to all strings String.prototype.reverse = function() { return Array.from(this).reverse().join(""); } function emailParts(email) { return email.toLowerCase().split("@") } // Defines a Phrase object function Phrase(content) { this.content = content; // Processes a string for palindrome checking // Returns content processed for palindrome testing. this.processedContent = function processedContent() { return this.letters().toLowerCase(); } this.palindrome = function palindrome() { if (this.letters()) { return this.processedContent() === this.processedContent().reverse(); } else { return false; } } this.louder = function louder() { return this.content.toUpperCase(); } this.letters = function() { const lettersRE = /[a-z]/ig; return (this.content.match(lettersRE) || []).join("") } }