-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (27 loc) · 970 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
module.exports = Phrase;
// reverse()メソッドを追加してすべてのStringで使えるようにする
String.prototype.reverse = function () {
return Array.from(this).reverse().join("");
};
// Phraseオブジェクトを定義する
function Phrase(content) {
this.content = content;
// パリンドロームのテスト用に変換した訳文を返す
this.processedContent = function processedContent() {
return this.letters().toLowerCase();
};
// コンテンツの文字だけを返す
// 利用例:
// new Phrase("Hello, world!").letters() === "Helloworld"
this.letters = function letters() {
return (this.content.match(/[a-z]/gi) || []).join("");
};
// パリンドロームならtrueを、違うならfalseを返す
this.palindrome = function palindrome() {
if (this.processedContent()) {
return this.processedContent() === this.processedContent().reverse();
} else {
return false;
}
};
}