Skip to content

Commit 2b1ba0e

Browse files
committed
refactored quiz2
1 parent 477d25f commit 2b1ba0e

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

quiz/2_address-book/src/index.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
interface PhoneNumberDictionary {
2-
[phoneNumber: string]: {
2+
[phone: string]: {
33
num: number;
44
};
55
}
66

77
interface Contact {
88
name: string;
99
address: string;
10-
phoneNumbers: PhoneNumberDictionary;
10+
phones: PhoneNumberDictionary;
1111
}
1212

1313
// api
14-
function fetchContacts(): Promise<Contact[]> {
15-
const contacts: Contact[] = [
14+
// TODO: 아래 함수의 반환 타입을 지정해보세요.
15+
function fetchContacts() {
16+
// TODO: 아래 변수의 타입을 지정해보세요.
17+
const contacts = [
1618
{
1719
name: 'Tony',
1820
address: 'Malibu',
19-
phoneNumbers: {
21+
phones: {
2022
home: {
2123
num: 11122223333,
2224
},
@@ -28,7 +30,7 @@ function fetchContacts(): Promise<Contact[]> {
2830
{
2931
name: 'Banner',
3032
address: 'New York',
31-
phoneNumbers: {
33+
phones: {
3234
home: {
3335
num: 77788889999,
3436
},
@@ -37,7 +39,7 @@ function fetchContacts(): Promise<Contact[]> {
3739
{
3840
name: '마동석',
3941
address: '서울시 강남구',
40-
phoneNumbers: {
42+
phones: {
4143
home: {
4244
num: 213423452,
4345
},
@@ -54,6 +56,7 @@ function fetchContacts(): Promise<Contact[]> {
5456

5557
// main
5658
class AddressBook {
59+
// TODO: 아래 변수의 타입을 지정해보세요.
5760
contacts = [];
5861

5962
constructor() {
@@ -66,6 +69,7 @@ class AddressBook {
6669
});
6770
}
6871

72+
/* TODO: 아래 함수들의 파라미터 타입과 반환 타입을 지정해보세요 */
6973
findContactByName(name) {
7074
return this.contacts.filter(contact => contact.name === name);
7175
}
@@ -74,8 +78,10 @@ class AddressBook {
7478
return this.contacts.filter(contact => contact.address === address);
7579
}
7680

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+
);
7985
}
8086

8187
addContact(contact) {
@@ -89,6 +95,7 @@ class AddressBook {
8995
displayListByAddress() {
9096
return this.contacts.map(contact => contact.address);
9197
}
98+
/* ------------------------------------------------ */
9299
}
93100

94101
new AddressBook();

quiz/2_address-book/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"checkJs": true,
55
"target": "es5",
66
"lib": ["es2015", "dom", "dom.iterable"],
7-
"noImplicitAny": false,
7+
"noImplicitAny": false
88
},
9-
"include": ["./src/**/*"],
9+
"include": ["./src/**/*"]
1010
}

0 commit comments

Comments
 (0)