@@ -4,22 +4,20 @@ const readFile = util.promisify(fs.readFile);
4
4
5
5
class MailSystem {
6
6
write ( name ) {
7
- // 修改 MailSystem 的 write 方法,使其返回包含名稱的特定內容
8
7
console . log ( '--write mail for ' + name + '--' ) ;
9
8
const context = 'Congrats, ' + name + '!' ;
10
9
return context ;
11
10
}
12
11
13
12
send ( name , context ) {
14
- // 修改 MailSystem 的 send 方法,模擬發送郵件並隨機返回成功或失敗
15
13
console . log ( '--send mail to ' + name + '--' ) ;
16
- const success = Math . random ( ) > 0.5 ; // 模擬郵件發送的隨機成功或失敗
14
+ const success = Math . random ( ) > 0.5 ;
17
15
if ( success ) {
18
16
console . log ( 'mail sent' ) ;
19
17
} else {
20
18
console . log ( 'mail failed' ) ;
21
19
}
22
- return success ; // 返回發送成功或失敗的結果
20
+ return success ;
23
21
}
24
22
}
25
23
@@ -35,21 +33,18 @@ class Application {
35
33
}
36
34
37
35
async getNames ( ) {
38
- // 修改 getNames 方法,使其從文件中讀取名稱列表
39
36
const data = await readFile ( 'name_list.txt' , 'utf8' ) ;
40
37
const people = data . split ( '\n' ) ;
41
38
const selected = [ ] ;
42
39
return [ people , selected ] ;
43
40
}
44
41
45
42
getRandomPerson ( ) {
46
- // 修改 getRandomPerson 方法,隨機返回一個名稱
47
43
const i = Math . floor ( Math . random ( ) * this . people . length ) ;
48
44
return this . people [ i ] ;
49
45
}
50
46
51
47
selectNextPerson ( ) {
52
- // 修改 selectNextPerson 方法,隨機選擇並返回一個未被選擇過的名稱
53
48
console . log ( '--select next person--' ) ;
54
49
if ( this . people . length === this . selected . length ) {
55
50
console . log ( 'all selected' ) ;
@@ -64,7 +59,6 @@ class Application {
64
59
}
65
60
66
61
notifySelected ( ) {
67
- // 修改 notifySelected 方法,通知所有已選擇的人
68
62
console . log ( '--notify selected--' ) ;
69
63
for ( const x of this . selected ) {
70
64
const context = this . mailSystem . write ( x ) ;
0 commit comments