33 lines
884 B
JavaScript
33 lines
884 B
JavaScript
// Reverses a string.
|
|
function reverse(string) {
|
|
return Array.from(string).reverse().join("");
|
|
}
|
|
|
|
// Defines a Phrase object.
|
|
function Phrase(content) {
|
|
this.content = content;
|
|
|
|
// Returns content processed for palindrome testing.
|
|
this.processedContent = function processedContent() {
|
|
return this.content.toLowerCase();
|
|
}
|
|
|
|
// Returns true if the phrase is a palindrome, false otherwise.
|
|
this.palindrome = function palindrome() {
|
|
return this.processedContent() === reverse(this.processedContent());
|
|
}
|
|
}
|
|
|
|
// Defines a TranslatedPhrase object.
|
|
function TranslatedPhrase(content, translation) {
|
|
this.content = content;
|
|
this.translation = translation;
|
|
|
|
// Returns translation processed for palindrome testing.
|
|
this.processedContent = function processedContent() {
|
|
return this.translation.toLowerCase();
|
|
}
|
|
}
|
|
|
|
TranslatedPhrase.prototype = new Phrase();
|