-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (32 loc) · 959 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module.exports = Phrase;
//Adds `reverse` to all strings
String.prototype.reverse = function reverse() {
return Array.from(this).reverse().join("");
}
String.prototype.blank = function blank() {
return (this.length === 0 || /^\s*$/.test(this));
}
// Defines a Phrase object
function Phrase(content) {
this.content = content;
this.processor = function(string) {
return string.toLowerCase();
}
// Returns content processed for palindrome testing
this.processedContent = function processedContent() {
return this.processor(this.letters());
}
// Returns the letters of the content.
this.letters = function letters() {
const lettersRegEx = /[a-z]/ig;
return (this.content.match(lettersRegEx) || []).join("");
}
// Returns true for a palindrome, false otherwise.
this.palindrome = function palindrome() {
if (this.letters()) {
return this.processedContent() === this.processedContent().reverse();
} else {
return false;
}
}
}