@@ -17,11 +17,16 @@ function addNewContact(contact) {
1717 const hasPhoneNumbers = contact . hasOwnProperty ( 'phoneNumbers' )
1818 const hasEmailAddresses = contact . hasOwnProperty ( 'emailAddresses' )
1919
20- if ( hasFirstName && typeof contact . firstName !== 'string' ) throw new TypeError ( 'firstName must be a string' )
21- if ( hasLastName && typeof contact . lastName !== 'string' ) throw new TypeError ( 'lastName must be a string' )
22- if ( hasNickname && typeof contact . nickname !== 'string' ) throw new TypeError ( 'nickname must be a string' )
23- if ( hasPhoneNumbers && ! Array . isArray ( contact . phoneNumbers ) ) throw new TypeError ( 'phoneNumbers must be an array' )
24- if ( hasEmailAddresses && ! Array . isArray ( contact . emailAddresses ) ) throw new TypeError ( 'emailAddresses must be an array' )
20+ if ( hasFirstName && typeof contact . firstName !== 'string' )
21+ throw new TypeError ( 'firstName must be a string' )
22+ if ( hasLastName && typeof contact . lastName !== 'string' )
23+ throw new TypeError ( 'lastName must be a string' )
24+ if ( hasNickname && typeof contact . nickname !== 'string' )
25+ throw new TypeError ( 'nickname must be a string' )
26+ if ( hasPhoneNumbers && ! Array . isArray ( contact . phoneNumbers ) )
27+ throw new TypeError ( 'phoneNumbers must be an array' )
28+ if ( hasEmailAddresses && ! Array . isArray ( contact . emailAddresses ) )
29+ throw new TypeError ( 'emailAddresses must be an array' )
2530
2631 if ( hasBirthday ) {
2732 const datePattern = / ^ \d { 4 } \- ( 0 [ 1 - 9 ] | 1 [ 0 1 2 ] ) \- ( 0 [ 1 - 9 ] | [ 1 2 ] [ 0 - 9 ] | 3 [ 0 1 ] ) $ /
@@ -47,11 +52,16 @@ function updateContact(contact) {
4752 const hasPhoneNumbers = contact . hasOwnProperty ( 'phoneNumbers' )
4853 const hasEmailAddresses = contact . hasOwnProperty ( 'emailAddresses' )
4954
50- if ( hasFirstName && typeof contact . firstName !== 'string' ) throw new TypeError ( 'firstName must be a string' )
51- if ( hasLastName && typeof contact . lastName !== 'string' ) throw new TypeError ( 'lastName must be a string' )
52- if ( hasNickname && typeof contact . nickname !== 'string' ) throw new TypeError ( 'nickname must be a string' )
53- if ( hasPhoneNumbers && ! Array . isArray ( contact . phoneNumbers ) ) throw new TypeError ( 'phoneNumbers must be an array' )
54- if ( hasEmailAddresses && ! Array . isArray ( contact . emailAddresses ) ) throw new TypeError ( 'emailAddresses must be an array' )
55+ if ( hasFirstName && typeof contact . firstName !== 'string' )
56+ throw new TypeError ( 'firstName must be a string' )
57+ if ( hasLastName && typeof contact . lastName !== 'string' )
58+ throw new TypeError ( 'lastName must be a string' )
59+ if ( hasNickname && typeof contact . nickname !== 'string' )
60+ throw new TypeError ( 'nickname must be a string' )
61+ if ( hasPhoneNumbers && ! Array . isArray ( contact . phoneNumbers ) )
62+ throw new TypeError ( 'phoneNumbers must be an array' )
63+ if ( hasEmailAddresses && ! Array . isArray ( contact . emailAddresses ) )
64+ throw new TypeError ( 'emailAddresses must be an array' )
5565
5666 if ( hasBirthday ) {
5767 const datePattern = / ^ \d { 4 } \- ( 0 [ 1 - 9 ] | 1 [ 0 1 2 ] ) \- ( 0 [ 1 - 9 ] | [ 1 2 ] [ 0 - 9 ] | 3 [ 0 1 ] ) $ /
@@ -78,5 +88,5 @@ module.exports = {
7888 getContactsByName,
7989 addNewContact,
8090 deleteContact,
81- updateContact
82- }
91+ updateContact,
92+ }
0 commit comments