1- //function User() {
2- // return {};
3- //}
1+ function User ( addArgument ) {
2+ this . name = addArgument . name ;
3+ this . surname = addArgument . surname ;
4+ this . number = addArgument . number ;
5+ this . city = addArgument . city ;
6+ this . company = addArgument . company ;
7+ }
48
59function PhoneApp ( ) {
610 this . storage = [ ] ;
@@ -21,8 +25,8 @@ PhoneApp.prototype.isNumber = function(stringToCheck) {
2125 return flag !== false ;
2226}
2327
24- PhoneApp . prototype . formatedPhoneNumber = function ( numberToSort ) {
25- const toStringTheNumber = numberToSort . toString ( ) ;
28+ PhoneApp . prototype . createFormatedPhoneNumber = function ( phoneNumber ) {
29+ const toStringTheNumber = phoneNumber . toString ( ) ;
2630 const toArrayTheString = toStringTheNumber . split ( '' ) ;
2731 let rewritedArray = [ ] ;
2832
@@ -57,22 +61,11 @@ PhoneApp.prototype.formatedPhoneNumber = function(numberToSort) {
5761 }
5862}
5963
60- //PhoneApp.prototype.add = function(name, number, surname = null, city = null, company = null) {
61- // const idNumber = this.storage.length + 1;
62- // const contact = new User();
63- // contact.id = idNumber;
64- // contact.name = name;
65- // contact.surname = surname;
66- // contact.number = this.formatedPhoneNumber(number);
67- // contact.city = city;
68- // contact.company = company;
69- // this.storage.push(contact);
70- //}
7164PhoneApp . prototype . add = function ( object ) {
7265 const idNumber = this . storage . length + 1 ;
73- const contact = object ;
66+ const contact = new User ( object ) ;
7467 contact . id = idNumber ;
75- contact . number = this . formatedPhoneNumber ( contact . number )
68+ contact . number = this . createFormatedPhoneNumber ( contact . number )
7669 this . storage . push ( contact ) ;
7770}
7871
@@ -116,9 +109,9 @@ PhoneApp.prototype.changeValueByIndex = function(index, key, value) {
116109const test = new PhoneApp ( ) ;
117110
118111test . add ( { name : 'Nikita' , number : '1234567890' , surname : 'Balashov' , city : 'Kharkiv' , company : null } ) ;
119- test . add ( { name : 'Nikita' , number : '0987655321' , surname : 'Smith' , city : null , comapny : null } ) ;
112+ test . add ( { name : 'Nikita' , number : '0987655321' , surname : 'Smith' , city : null , company : null } ) ;
120113test . add ( { name : 'Paul' , number : '0893127823' , surname : 'Smith' , city : 'Kharkiv' , company : null } ) ;
121- test . add ( { name : 'Paul' , number : '0897612374' , surname : 'Balashov' , city : null , comapny : null } ) ;
114+ test . add ( { name : 'Paul' , number : '0897612374' , surname : 'Balashov' , city : null , company : null } ) ;
122115
123116console . log ( test . storage ) ;
124117console . log ( test . filterByValue ( 'name' , 'Nikita' ) ) ;
0 commit comments