-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Лопатин Николай #93
base: master
Are you sure you want to change the base?
Лопатин Николай #93
Conversation
🍅 Пройдено тестов 16 из 26 |
🍅 Не пройден линтинг или базовые тесты |
🍅 Пройдено тестов 16 из 26 |
🍅 Пройдено тестов 16 из 26 |
🍅 Пройдено тестов 17 из 26 |
🍅 Пройдено тестов 17 из 26 |
🍅 Пройдено тестов 18 из 26 |
🍅 Пройдено тестов 18 из 26 |
🍅 Пройдено тестов 18 из 26 |
🍅 Пройдено тестов 22 из 26 |
🍅 Пройдено тестов 22 из 26 |
🍅 Пройдено тестов 22 из 26 |
🍅 Пройдено тестов 19 из 23 |
🍅 Пройдено тестов 22 из 26 |
🍅 Пройдено тестов 22 из 26 |
🍅 Пройдено тестов 22 из 26 |
🍅 Пройдено тестов 22 из 26 |
🍅 Пройдено тестов 22 из 26 |
🍅 Пройдено тестов 22 из 26 |
🍏 Пройдено тестов 26 из 26 |
@plotnikovn обрати внимание: решено доп. задание |
|
||
function check(phone, name) { | ||
if (typeof phone !== 'string' || typeof name !== 'string' || name.length <= 0 || | ||
phone <= 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
– длина строки не может быть отрицательной
– phone <= 0
не лучшая идея сравнивать на строку с числом
return false; | ||
} | ||
|
||
return /^\d{10}$/.test(phone); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
длину телефона можно не проверять, т.к. в регулярном выражении ты задаешь фиксированное количество символов
return /^\d{10}$/.test(phone); | ||
} | ||
|
||
function check2(email) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
давай осмысленные названия функциям
return false; | ||
} | ||
} | ||
if (email === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут лучше поменять местами, и тогда проверка станет проще
if (email === undefined) {
return true;
}
return typeof email === 'string' && email.length;
} | ||
|
||
function generalCheck(phone, name, email) { | ||
if (check(phone, name) === false || check2(email) === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
можно сразу сделать return
return check(…) || check2(…);
@@ -19,7 +54,17 @@ let phoneBook; | |||
* @returns {Boolean} | |||
*/ | |||
function add(phone, name, email) { | |||
if (generalCheck(phone, name, email) === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!generalCheck(…)) {
…
}
if (generalCheck(phone, name, email) === false) { | ||
return false; | ||
} | ||
if (checkPhone(phone) === true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
аналогично
if (generalCheck(phone, name, email) === false) { | ||
return false; | ||
} | ||
phoneBook.forEach(element => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
здесь лучше подойдет .some
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/some
if (element.phone.includes(query) === true || | ||
element.name.includes(query) === true || | ||
(element.email ? element.email.includes(query) : false)) { | ||
string = element.name + ', +7 (' + element.phone.slice(0, 3) + ') ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше сделать отдельную функцию для форматирования записи
No description provided.