-
Notifications
You must be signed in to change notification settings - Fork 16
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
js_task_2 task_1 task_2 #20
base: master
Are you sure you want to change the base?
js_task_2 task_1 task_2 #20
Conversation
src/task_1/index.js
Outdated
const typeOfPhone_2 = new RegExp("^\\+7\\d{10}$"); | ||
const typeOfEmail = new RegExp("^\\w+@\\w+\\.\\w+$"); | ||
|
||
let item = {} |
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.
item
нигде не переприсвается, лучше в таких случаях использовать const вместо let
src/task_1/index.js
Outdated
@@ -20,6 +20,50 @@ | |||
@returns {boolean} Результат добавления | |||
*/ | |||
function add(phoneBook, phone, name, email) { | |||
const typeOfPhone_1 = new RegExp("^\\+7\\-\\d{3}\\-\\d{3}\\-\\d{2}\\-\\d{2}$"); |
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.
Следует придерживаться одного стиля именования переменных, для js это предпочтительно camelCase, а у тебя тут смешанный camelCase и snake_case.
src/task_1/index.js
Outdated
@@ -20,6 +20,50 @@ | |||
@returns {boolean} Результат добавления | |||
*/ | |||
function add(phoneBook, phone, name, email) { | |||
const typeOfPhone_1 = new RegExp("^\\+7\\-\\d{3}\\-\\d{3}\\-\\d{2}\\-\\d{2}$"); | |||
const typeOfPhone_2 = new RegExp("^\\+7\\d{10}$"); |
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.
Аналогично комменту выше
src/task_1/index.js
Outdated
|
||
let item = {} | ||
|
||
if (phone.match(typeOfPhone_1)) { |
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.
метод match возвращает сопоставленное значение, ты его нигде не используешь, тут будет уместнее использовать метод test() у регулярки, который возвращает bool
src/task_1/index.js
Outdated
if (phone.match(typeOfPhone_1)) { | ||
item.phone = phone; | ||
} | ||
else if(phone.match(typeOfPhone_2)) { |
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ом, если написать через логический оператор ИЛИ
src/task_3/index.js
Outdated
function find(phoneBook, query) { | ||
if (query === '*') { | ||
let firstAr = []; |
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.
const. Почему бы не сделать один общий массив результатов, и возвращать его, нежели каждый раз плодить новый
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.
ок, сделал
src/task_3/index.js
Outdated
|
||
let oldFormatPhone = phoneBook[key].phone; // +7-922-555-35-35 | ||
|
||
let newOne = oldFormatPhone.replace(/(\+\d)(\-?)(\d{3})(\-?)(\d{3})(\-?)(\d{2})(\-?)(\d{2})/, |
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.
Вынести повторяющуюся функциональности в 3х ifах в отдельную функицю
src/task_3/index.js
Outdated
} | ||
|
||
} | ||
return thirdAr |
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.
А где сортировка по имени?
src/task_4/index.js
Outdated
return array_1.length; | ||
} | ||
|
||
else if (query === 'andrey') { |
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.
Используй написанный метод find в предыдущем задании, а здесь напиши только удаление
src/task_5/index.js
Outdated
if (item.match(typeOfPhone_1)) { | ||
objItem.phone = item; | ||
} | ||
else if (item.match(typeOfPhone_2)) { |
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.
Комменты из 1го задания актуальны
@Toouren