Skip to content

Commit 6ce2158

Browse files
Balashov NikitaOlegLustenko
authored andcommitted
little fixes
1 parent 46a7617 commit 6ce2158

File tree

1 file changed

+32
-23
lines changed
  • js-core/homeworks/phoneApp/src

1 file changed

+32
-23
lines changed

js-core/homeworks/phoneApp/src/main.js

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//function User() {
2+
// return {};
3+
//}
4+
15
function PhoneApp() {
26
this.storage = [];
37
}
@@ -42,40 +46,46 @@ PhoneApp.prototype.formatedPhoneNumber = function(numberToSort) {
4246

4347
let lastNumbers = joinRewritedArray.slice(7, joinRewritedArray.length);
4448

45-
const finalConstraction = bracketThisFirstThreeNumbers +
49+
const formatedPhoneNumber = bracketThisFirstThreeNumbers +
4650
bracketThisSecondTwoNumbers +
4751
bracketThisThirdTwoNumbers +
4852
lastNumbers;
4953

50-
return finalConstraction;
54+
return formatedPhoneNumber;
5155
} else {
5256
return console.log('EROR you had typed incorect number')
5357
}
5458
}
5559

56-
PhoneApp.prototype.add = function(name, number, surname = null, city = null, company = null) {
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+
//}
71+
PhoneApp.prototype.add = function(object) {
5772
const idNumber = this.storage.length + 1;
58-
const contact = {
59-
id: idNumber,
60-
name: name,
61-
surname: surname,
62-
number: this.formatedPhoneNumber(number),
63-
city: city,
64-
company: company
65-
}
73+
const contact = object;
74+
contact.id = idNumber;
75+
contact.number = this.formatedPhoneNumber(contact.number)
6676
this.storage.push(contact);
6777
}
6878

6979
PhoneApp.prototype.filterByValue = function(key, value) {
70-
return this.storage.filter((elem, index) => {
71-
return elem[key] === value;
80+
return this.storage.filter(user => {
81+
return user[key] === value;
7282
});
7383
}
7484

75-
PhoneApp.prototype.sortByKey = function(key) {
76-
const sortFunction = function(a, b) {
77-
if(a[key] > b[key]) return 1;
78-
if(a[key] < b[key]) return -1;
85+
PhoneApp.prototype.sortUsersByValue = function(key) {
86+
const sortFunction = function(value, nextValue) {
87+
if(value[key] > nextValue[key]) return 1;
88+
if(value[key] < nextValue[key]) return -1;
7989
}
8090

8191
let copyStorage = [...this.storage]
@@ -105,14 +115,13 @@ PhoneApp.prototype.changeValueByIndex = function(index, key, value) {
105115

106116
const test = new PhoneApp();
107117

108-
test.add('Nikita', '1234567890', 'Balashov', 'Kharkiv');
109-
test.add('Nikita', '0987655321', 'Smith');
110-
test.add('Paul', '0893127823', 'Smith', 'Kharkiv');
111-
test.add('Paul', '0897612374', 'Balashov');
118+
test.add({name: 'Nikita', number: '1234567890', surname: 'Balashov', city: 'Kharkiv', company: null});
119+
test.add({name: 'Nikita', number: '0987655321', surname: 'Smith', city: null, comapny: null});
120+
test.add({name: 'Paul', number: '0893127823', surname: 'Smith', city: 'Kharkiv', company: null});
121+
test.add({name: 'Paul', number: '0897612374', surname: 'Balashov', city: null, comapny: null});
112122

113123
console.log(test.storage);
114124
console.log(test.filterByValue('name', 'Nikita'));
115125
console.log(test.filterByValue('name', 'Paul'));
116126
console.log(test.filterByValue('city', 'Kharkiv'));
117-
console.log(test.filterByValue('surname', 'Balashov'));
118-
test.isNumber('099-13-15-100')
127+
console.log(test.filterByValue('surname', 'Balashov'));

0 commit comments

Comments
 (0)