1
1
interface PhoneNumberDictionary {
2
- [ phoneNumber : string ] : {
2
+ [ phone : string ] : {
3
3
num : number ;
4
4
} ;
5
5
}
6
6
7
7
interface Contact {
8
8
name : string ;
9
9
address : string ;
10
- phoneNumbers : PhoneNumberDictionary ;
10
+ phones : PhoneNumberDictionary ;
11
11
}
12
12
13
13
// api
14
- function fetchContacts ( ) : Promise < Contact [ ] > {
15
- const contacts : Contact [ ] = [
14
+ // TODO: 아래 함수의 반환 타입을 지정해보세요.
15
+ function fetchContacts ( ) {
16
+ // TODO: 아래 변수의 타입을 지정해보세요.
17
+ const contacts = [
16
18
{
17
19
name : 'Tony' ,
18
20
address : 'Malibu' ,
19
- phoneNumbers : {
21
+ phones : {
20
22
home : {
21
23
num : 11122223333 ,
22
24
} ,
@@ -28,7 +30,7 @@ function fetchContacts(): Promise<Contact[]> {
28
30
{
29
31
name : 'Banner' ,
30
32
address : 'New York' ,
31
- phoneNumbers : {
33
+ phones : {
32
34
home : {
33
35
num : 77788889999 ,
34
36
} ,
@@ -37,7 +39,7 @@ function fetchContacts(): Promise<Contact[]> {
37
39
{
38
40
name : '마동석' ,
39
41
address : '서울시 강남구' ,
40
- phoneNumbers : {
42
+ phones : {
41
43
home : {
42
44
num : 213423452 ,
43
45
} ,
@@ -54,6 +56,7 @@ function fetchContacts(): Promise<Contact[]> {
54
56
55
57
// main
56
58
class AddressBook {
59
+ // TODO: 아래 변수의 타입을 지정해보세요.
57
60
contacts = [ ] ;
58
61
59
62
constructor ( ) {
@@ -66,6 +69,7 @@ class AddressBook {
66
69
} ) ;
67
70
}
68
71
72
+ /* TODO: 아래 함수들의 파라미터 타입과 반환 타입을 지정해보세요 */
69
73
findContactByName ( name ) {
70
74
return this . contacts . filter ( contact => contact . name === name ) ;
71
75
}
@@ -74,8 +78,10 @@ class AddressBook {
74
78
return this . contacts . filter ( contact => contact . address === address ) ;
75
79
}
76
80
77
- findContactByPhone ( phoneNumber , type ) {
78
- return this . contacts . filter ( contact => contact . phone [ type ] === phoneNumber ) ;
81
+ findContactByPhone ( phoneNumber , phoneType : string ) {
82
+ return this . contacts . filter (
83
+ contact => contact . phones [ phoneType ] . num === phoneNumber
84
+ ) ;
79
85
}
80
86
81
87
addContact ( contact ) {
@@ -89,6 +95,7 @@ class AddressBook {
89
95
displayListByAddress ( ) {
90
96
return this . contacts . map ( contact => contact . address ) ;
91
97
}
98
+ /* ------------------------------------------------ */
92
99
}
93
100
94
101
new AddressBook ( ) ;
0 commit comments