From 82479ad53c5d09165e9206bf7ea9e3427e9a9428 Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 25 Oct 2018 17:25:45 +0500 Subject: [PATCH 01/33] =?UTF-8?q?=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D0=B2=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 71 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/phone-book.js b/phone-book.js index 891d7c01..c22203a9 100644 --- a/phone-book.js +++ b/phone-book.js @@ -9,7 +9,21 @@ const isStar = true; /** * Телефонная книга */ -let phoneBook; +let phoneBook = {}; + +/** + * Проверка параметров + * @param {String} phone + * @param {String?} name + * @param {String?} email + * @returns {Boolean} + */ +function trueParam(phone, name, email) { + var tel = /(^[0-9]{10}$)/; + + return (typeof phone === 'string') && (tel.test(phone)) && (name !== '') && + (email === undefined || typeof email === 'string'); +} /** * Добавление записи в телефонную книгу @@ -19,7 +33,12 @@ let phoneBook; * @returns {Boolean} */ function add(phone, name, email) { + if (find(phone).length > 0 || (!trueParam(phone, name, email))) { + return false; + } + phoneBook[phone] = { name: name, email: email }; + return true; } /** @@ -30,7 +49,13 @@ function add(phone, name, email) { * @returns {Boolean} */ function update(phone, name, email) { + if (find(phone).length > 0 && (trueParam(phone, name, email))) { + phoneBook[phone] = { name: name, email: email }; + + return true; + } + return false; } /** @@ -39,7 +64,16 @@ function update(phone, name, email) { * @returns {Number} */ function findAndRemove(query) { + if (query === '') { + return 0; + } + var count = 0; + for (var [key] of Object.entries(phoneBook)) { + delete phoneBook[key]; + count++; + } + return count; } /** @@ -48,7 +82,29 @@ function findAndRemove(query) { * @returns {String[]} */ function find(query) { + if (query === '') { + return []; + } + if (query === '*') { + query = ''; + } + const result = []; + var res = ''; + for (var [key, value] of Object.entries(phoneBook)) { + var newPhone = newNumber(key); + res = value.name + ',' + newPhone; + if (value.email !== undefined) { + res += ',' + value.email; + } + } + result.push(res); + + return result.sort(); +} + +function newNumber(phone) { + return phone.replace(/^(\d{3})(\d{3})(\d{2})(\d{2})$/, '+7 ($1) $2-$3-$4'); } /** @@ -61,8 +117,19 @@ function importFromCsv(csv) { // Парсим csv // Добавляем в телефонную книгу // Либо обновляем, если запись с таким телефоном уже существует + if (csv === undefined || typeof (csv) !== 'string' || csv === '') { + return 0; + } + var count = 0; + var text = csv.split(';'); + var name = text[0]; + var phone = text[1]; + var email = text[2]; + if (add(phone, name, email) || update(phone, name, email)) { + count++; + } - return csv.split('\n').length; + return count; } module.exports = { From ed0b546145e5da40abaed67925b312f5e04f6e8c Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 25 Oct 2018 17:38:11 +0500 Subject: [PATCH 02/33] =?UTF-8?q?=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D0=B2=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phone-book.js b/phone-book.js index c22203a9..7eae051a 100644 --- a/phone-book.js +++ b/phone-book.js @@ -33,7 +33,7 @@ function trueParam(phone, name, email) { * @returns {Boolean} */ function add(phone, name, email) { - if (find(phone).length > 0 || (!trueParam(phone, name, email))) { + if (!find(phone).length > 0 || !trueParam(phone, name, email)) { return false; } phoneBook[phone] = { name: name, email: email }; @@ -128,7 +128,7 @@ function importFromCsv(csv) { if (add(phone, name, email) || update(phone, name, email)) { count++; } - + return csv.split('\n').length; return count; } From cbfc6344a23404fadf6bf148197c552b3fe1b96a Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 25 Oct 2018 17:41:41 +0500 Subject: [PATCH 03/33] =?UTF-8?q?=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D0=B2=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phone-book.js b/phone-book.js index 7eae051a..d76a3098 100644 --- a/phone-book.js +++ b/phone-book.js @@ -128,7 +128,7 @@ function importFromCsv(csv) { if (add(phone, name, email) || update(phone, name, email)) { count++; } - return csv.split('\n').length; + return count; } From f09eb4c08469528f4829bbd16e939f253cf5980f Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 25 Oct 2018 21:27:45 +0500 Subject: [PATCH 04/33] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BA=D0=B8=C3=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/phone-book.js b/phone-book.js index d76a3098..0a3baa39 100644 --- a/phone-book.js +++ b/phone-book.js @@ -33,7 +33,7 @@ function trueParam(phone, name, email) { * @returns {Boolean} */ function add(phone, name, email) { - if (!find(phone).length > 0 || !trueParam(phone, name, email)) { + if (phoneBook.hasOwnProperty(phone) || !trueParam(phone, name, email)) { return false; } phoneBook[phone] = { name: name, email: email }; @@ -49,7 +49,7 @@ function add(phone, name, email) { * @returns {Boolean} */ function update(phone, name, email) { - if (find(phone).length > 0 && (trueParam(phone, name, email))) { + if (phoneBook.hasOwnProperty(phone).length > 0 && (trueParam(phone, name, email))) { phoneBook[phone] = { name: name, email: email }; return true; @@ -120,8 +120,9 @@ function importFromCsv(csv) { if (csv === undefined || typeof (csv) !== 'string' || csv === '') { return 0; } + const newCsv = csv.split('\n'); var count = 0; - var text = csv.split(';'); + var text = newCsv.split(';'); var name = text[0]; var phone = text[1]; var email = text[2]; From 67238514b2975b6bfc7d2a7f3ea1b1ab4cc55734 Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 25 Oct 2018 21:32:20 +0500 Subject: [PATCH 05/33] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phone-book.js b/phone-book.js index 0a3baa39..0ddc672d 100644 --- a/phone-book.js +++ b/phone-book.js @@ -22,7 +22,7 @@ function trueParam(phone, name, email) { var tel = /(^[0-9]{10}$)/; return (typeof phone === 'string') && (tel.test(phone)) && (name !== '') && - (email === undefined || typeof email === 'string'); + (name !== undefined) && (email === undefined || typeof email === 'string'); } /** @@ -33,7 +33,7 @@ function trueParam(phone, name, email) { * @returns {Boolean} */ function add(phone, name, email) { - if (phoneBook.hasOwnProperty(phone) || !trueParam(phone, name, email)) { + if (phoneBook.find(phone) || !trueParam(phone, name, email)) { return false; } phoneBook[phone] = { name: name, email: email }; @@ -49,7 +49,7 @@ function add(phone, name, email) { * @returns {Boolean} */ function update(phone, name, email) { - if (phoneBook.hasOwnProperty(phone).length > 0 && (trueParam(phone, name, email))) { + if (phoneBook.find(phone).length > 0 && (trueParam(phone, name, email))) { phoneBook[phone] = { name: name, email: email }; return true; From 90b7643be25bb070b6796b54acc5db43bdaf7829 Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 25 Oct 2018 21:36:22 +0500 Subject: [PATCH 06/33] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phone-book.js b/phone-book.js index 0ddc672d..106440d8 100644 --- a/phone-book.js +++ b/phone-book.js @@ -33,7 +33,7 @@ function trueParam(phone, name, email) { * @returns {Boolean} */ function add(phone, name, email) { - if (phoneBook.find(phone) || !trueParam(phone, name, email)) { + if (find(phone) || !trueParam(phone, name, email)) { return false; } phoneBook[phone] = { name: name, email: email }; @@ -49,7 +49,7 @@ function add(phone, name, email) { * @returns {Boolean} */ function update(phone, name, email) { - if (phoneBook.find(phone).length > 0 && (trueParam(phone, name, email))) { + if (find(phone).length > 0 && (trueParam(phone, name, email))) { phoneBook[phone] = { name: name, email: email }; return true; From 7ac257be5ea32a154ac81c75fd96f287d49b6264 Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 25 Oct 2018 21:44:31 +0500 Subject: [PATCH 07/33] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/phone-book.js b/phone-book.js index 106440d8..680a37be 100644 --- a/phone-book.js +++ b/phone-book.js @@ -33,7 +33,7 @@ function trueParam(phone, name, email) { * @returns {Boolean} */ function add(phone, name, email) { - if (find(phone) || !trueParam(phone, name, email)) { + if (find(phone).length > 0 || !trueParam(phone, name, email)) { return false; } phoneBook[phone] = { name: name, email: email }; @@ -49,7 +49,7 @@ function add(phone, name, email) { * @returns {Boolean} */ function update(phone, name, email) { - if (find(phone).length > 0 && (trueParam(phone, name, email))) { + if (!find(phone).length > 0 && (trueParam(phone, name, email))) { phoneBook[phone] = { name: name, email: email }; return true; @@ -117,17 +117,19 @@ function importFromCsv(csv) { // Парсим csv // Добавляем в телефонную книгу // Либо обновляем, если запись с таким телефоном уже существует - if (csv === undefined || typeof (csv) !== 'string' || csv === '') { + if (csv === undefined || csv === '') { return 0; } const newCsv = csv.split('\n'); var count = 0; - var text = newCsv.split(';'); - var name = text[0]; - var phone = text[1]; - var email = text[2]; - if (add(phone, name, email) || update(phone, name, email)) { - count++; + for (var i = 0; i < newCsv.length; i++) { + var text = newCsv[i].split(';'); + var name = text[0]; + var phone = text[1]; + var email = text[2]; + if (add(phone, name, email) || update(phone, name, email)) { + count++; + } } return count; From 877fc7689e515f14945d1c2ed38ee1ea7bb0f8c9 Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 25 Oct 2018 22:03:39 +0500 Subject: [PATCH 08/33] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/phone-book.js b/phone-book.js index 680a37be..7743675a 100644 --- a/phone-book.js +++ b/phone-book.js @@ -33,10 +33,10 @@ function trueParam(phone, name, email) { * @returns {Boolean} */ function add(phone, name, email) { - if (find(phone).length > 0 || !trueParam(phone, name, email)) { + if (phoneBook[phone] || !trueParam(phone, name, email)) { return false; } - phoneBook[phone] = { name: name, email: email }; + phoneBook[phone] = { name, email }; return true; } @@ -49,7 +49,7 @@ function add(phone, name, email) { * @returns {Boolean} */ function update(phone, name, email) { - if (!find(phone).length > 0 && (trueParam(phone, name, email))) { + if (!phoneBook[phone] && (trueParam(phone, name, email))) { phoneBook[phone] = { name: name, email: email }; return true; @@ -85,8 +85,9 @@ function find(query) { if (query === '') { return []; } + var phones = Object.keys(phoneBook); if (query === '*') { - query = ''; + return phones; } const result = []; var res = ''; From d174d3ce2260109b20f1fdd34d0112154dd4077c Mon Sep 17 00:00:00 2001 From: Veronica Date: Sat, 27 Oct 2018 22:21:27 +0500 Subject: [PATCH 09/33] =?UTF-8?q?=D1=87=D1=82=D0=BE=20=D1=82=D0=BE=20?= =?UTF-8?q?=D0=BD=D0=B5=20=D1=82=D0=B0=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 71 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/phone-book.js b/phone-book.js index 7743675a..2b3a945d 100644 --- a/phone-book.js +++ b/phone-book.js @@ -49,13 +49,12 @@ function add(phone, name, email) { * @returns {Boolean} */ function update(phone, name, email) { - if (!phoneBook[phone] && (trueParam(phone, name, email))) { - phoneBook[phone] = { name: name, email: email }; - - return true; + if (phoneBook[phone] || !trueParam(phone, name, email) || !name) { + return false; } + phoneBook[phone] = { name, email }; - return false; + return true; } /** @@ -67,15 +66,30 @@ function findAndRemove(query) { if (query === '') { return 0; } + var res; var count = 0; - for (var [key] of Object.entries(phoneBook)) { - delete phoneBook[key]; - count++; + for (var phone of Object.keys(phoneBook)) { + res = matchSearch(phoneBook[phone], query); + if (res !== undefined) { + delete phoneBook[phone]; + count++; + } } return count; } +function matchSearch(record, query) { + if (query === '*') { + return record; + } + if (record[0].indexOf(query) !== -1 || record[1].indexOf(query) !== -1 || + (record[2] && record[2].indexOf(query) !== -1)) { + + return record; + } +} + /** * Поиск записей по запросу в телефонной книге * @param {String} query @@ -85,27 +99,42 @@ function find(query) { if (query === '') { return []; } - var phones = Object.keys(phoneBook); - if (query === '*') { - return phones; - } const result = []; - var res = ''; - for (var [key, value] of Object.entries(phoneBook)) { - var newPhone = newNumber(key); - res = value.name + ',' + newPhone; - if (value.email !== undefined) { - res += ',' + value.email; + var res; + for (var phone of Object.keys(phoneBook)) { + if (phoneBook[phone] === undefined) { + return []; + } + res = matchSearch(phoneBook[phone], query); + if (res !== undefined) { + result.push(res); } } - result.push(res); + var record; + record = view(result); - return result.sort(); + return record.sort(); } function newNumber(phone) { + return `+7 (${phone.substring(0, 3)}) ${phone.substring(3, 6)} + -${phone.substring(6, 8)}-${phone.substring(8)}`; +} + +function view(result) { + var recordSought = []; + for (let info of result) { + if (info[0] === undefined) { + return []; + } + if (info[2] !== undefined) { + recordSought.push(info[1] + ',' + newNumber(info[0]) + info[2]); + } else { + recordSought.push(info[1] + ',' + newNumber(info[0])); + } + } - return phone.replace(/^(\d{3})(\d{3})(\d{2})(\d{2})$/, '+7 ($1) $2-$3-$4'); + return recordSought; } /** From 9e50221d090669f496aee1f619617aca565bcfd8 Mon Sep 17 00:00:00 2001 From: Veronica Date: Sun, 28 Oct 2018 18:27:20 +0500 Subject: [PATCH 10/33] =?UTF-8?q?=D0=B4=D0=BE=D0=BE=D1=88=D0=B8=D0=B1?= =?UTF-8?q?=D0=BE=D1=87=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/phone-book.js b/phone-book.js index 2b3a945d..445ad63f 100644 --- a/phone-book.js +++ b/phone-book.js @@ -36,7 +36,11 @@ function add(phone, name, email) { if (phoneBook[phone] || !trueParam(phone, name, email)) { return false; } - phoneBook[phone] = { name, email }; + if (email === undefined) { + phoneBook[phone] = [phone, name]; + } else { + phoneBook[phone] = [phone, name, email]; + } return true; } @@ -52,7 +56,7 @@ function update(phone, name, email) { if (phoneBook[phone] || !trueParam(phone, name, email) || !name) { return false; } - phoneBook[phone] = { name, email }; + phoneBook[phone] = { phone, name, email }; return true; } @@ -124,7 +128,7 @@ function newNumber(phone) { function view(result) { var recordSought = []; for (let info of result) { - if (info[0] === undefined) { + if (info === undefined) { return []; } if (info[2] !== undefined) { From f014f2f806b4ce4be53b3b8c387965ebd66b691b Mon Sep 17 00:00:00 2001 From: Veronica Date: Sun, 28 Oct 2018 18:31:48 +0500 Subject: [PATCH 11/33] hello --- phone-book.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/phone-book.js b/phone-book.js index 445ad63f..423d801f 100644 --- a/phone-book.js +++ b/phone-book.js @@ -56,7 +56,11 @@ function update(phone, name, email) { if (phoneBook[phone] || !trueParam(phone, name, email) || !name) { return false; } - phoneBook[phone] = { phone, name, email }; + if (email === undefined) { + phoneBook[phone] = [phone, name]; + } else { + phoneBook[phone] = [phone, name, email]; + } return true; } From 17076db0a8176846c6ae750afca10edd0219eb6c Mon Sep 17 00:00:00 2001 From: Veronica Date: Sun, 28 Oct 2018 18:38:34 +0500 Subject: [PATCH 12/33] hello --- phone-book.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phone-book.js b/phone-book.js index 423d801f..028f546c 100644 --- a/phone-book.js +++ b/phone-book.js @@ -18,11 +18,11 @@ let phoneBook = {}; * @param {String?} email * @returns {Boolean} */ -function trueParam(phone, name, email) { +function trueParam(phone, name) { var tel = /(^[0-9]{10}$)/; return (typeof phone === 'string') && (tel.test(phone)) && (name !== '') && - (name !== undefined) && (email === undefined || typeof email === 'string'); + (name !== undefined) && (typeof name === 'string'); } /** @@ -53,7 +53,7 @@ function add(phone, name, email) { * @returns {Boolean} */ function update(phone, name, email) { - if (phoneBook[phone] || !trueParam(phone, name, email) || !name) { + if (phoneBook[phone] || !trueParam(phone, name, email)) { return false; } if (email === undefined) { @@ -104,7 +104,7 @@ function matchSearch(record, query) { * @returns {String[]} */ function find(query) { - if (query === '') { + if (query === '' || typeof(query) !== 'string') { return []; } const result = []; From a0d467bd58b25c5ffb21489b1b0fac0e26a039cb Mon Sep 17 00:00:00 2001 From: Veronica Date: Sun, 28 Oct 2018 18:42:04 +0500 Subject: [PATCH 13/33] hello --- phone-book.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/phone-book.js b/phone-book.js index 028f546c..ea18ef91 100644 --- a/phone-book.js +++ b/phone-book.js @@ -54,15 +54,16 @@ function add(phone, name, email) { */ function update(phone, name, email) { if (phoneBook[phone] || !trueParam(phone, name, email)) { - return false; - } - if (email === undefined) { - phoneBook[phone] = [phone, name]; - } else { - phoneBook[phone] = [phone, name, email]; + if (email === undefined) { + phoneBook[phone] = [phone, name]; + } else { + phoneBook[phone] = [phone, name, email]; + } + + return true; } - return true; + return false; } /** @@ -104,7 +105,7 @@ function matchSearch(record, query) { * @returns {String[]} */ function find(query) { - if (query === '' || typeof(query) !== 'string') { + if (query === '' || typeof (query) !== 'string') { return []; } const result = []; From b549743959cbc67686b88a6849577501a91eddf9 Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 29 Oct 2018 16:56:09 +0500 Subject: [PATCH 14/33] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 1 + 1 file changed, 1 insertion(+) diff --git a/phone-book.js b/phone-book.js index ea18ef91..87d98fb0 100644 --- a/phone-book.js +++ b/phone-book.js @@ -32,6 +32,7 @@ function trueParam(phone, name) { * @param {String?} email * @returns {Boolean} */ + function add(phone, name, email) { if (phoneBook[phone] || !trueParam(phone, name, email)) { return false; From 1049d541da14000b8959b734d925e5c16bb01f1d Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 29 Oct 2018 17:04:35 +0500 Subject: [PATCH 15/33] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/phone-book.js b/phone-book.js index 87d98fb0..2890c3d0 100644 --- a/phone-book.js +++ b/phone-book.js @@ -127,8 +127,7 @@ function find(query) { } function newNumber(phone) { - return `+7 (${phone.substring(0, 3)}) ${phone.substring(3, 6)} - -${phone.substring(6, 8)}-${phone.substring(8)}`; + return `+7 (${phone.slice(0, 3)}) ${phone.slice(3, 6)}-${phone.slice(6, 8)}-${phone.slice(8)}`; } function view(result) { @@ -138,9 +137,9 @@ function view(result) { return []; } if (info[2] !== undefined) { - recordSought.push(info[1] + ',' + newNumber(info[0]) + info[2]); + recordSought.push(info[1] + ', ' + newNumber(info[0]) + ', ' + info[2]); } else { - recordSought.push(info[1] + ',' + newNumber(info[0])); + recordSought.push(info[1] + ', ' + newNumber(info[0])); } } From f872bab42fe49cb8f0913b79028112b46b67377e Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 29 Oct 2018 17:16:21 +0500 Subject: [PATCH 16/33] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/phone-book.js b/phone-book.js index 2890c3d0..fcc7a55e 100644 --- a/phone-book.js +++ b/phone-book.js @@ -161,15 +161,14 @@ function importFromCsv(csv) { } const newCsv = csv.split('\n'); var count = 0; - for (var i = 0; i < newCsv.length; i++) { - var text = newCsv[i].split(';'); - var name = text[0]; - var phone = text[1]; - var email = text[2]; + newCsv.forEach(each => { + let phone = each.split(';')[1]; + let name = each.split(';')[0]; + let email = each.split(';')[2]; if (add(phone, name, email) || update(phone, name, email)) { count++; } - } + }); return count; } From fb52055fef8bc623eafe19273b506924595b3c78 Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 29 Oct 2018 17:27:49 +0500 Subject: [PATCH 17/33] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/phone-book.js b/phone-book.js index fcc7a55e..92d8d61c 100644 --- a/phone-book.js +++ b/phone-book.js @@ -161,14 +161,15 @@ function importFromCsv(csv) { } const newCsv = csv.split('\n'); var count = 0; - newCsv.forEach(each => { - let phone = each.split(';')[1]; - let name = each.split(';')[0]; - let email = each.split(';')[2]; + for (let value of newCsv) { + let contact = value.split(';'); + var phone = contact[1]; + var name = contact[0]; + var email = contact[2]; if (add(phone, name, email) || update(phone, name, email)) { count++; } - }); + } return count; } From 4332b66b86b21a80f7f49b3613002cb82739c53f Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 29 Oct 2018 17:32:56 +0500 Subject: [PATCH 18/33] =?UTF-8?q?=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/phone-book.js b/phone-book.js index 92d8d61c..659fd1b1 100644 --- a/phone-book.js +++ b/phone-book.js @@ -34,16 +34,18 @@ function trueParam(phone, name) { */ function add(phone, name, email) { - if (phoneBook[phone] || !trueParam(phone, name, email)) { - return false; - } - if (email === undefined) { - phoneBook[phone] = [phone, name]; - } else { - phoneBook[phone] = [phone, name, email]; + if (!phoneBook[phone] || trueParam(phone, name, email)) { + if (email === undefined) { + phoneBook[phone] = [phone, name]; + } else { + phoneBook[phone] = [phone, name, email]; + } + + return true; } - return true; + return false; + } /** @@ -54,7 +56,7 @@ function add(phone, name, email) { * @returns {Boolean} */ function update(phone, name, email) { - if (phoneBook[phone] || !trueParam(phone, name, email)) { + if (phoneBook[phone] && trueParam(phone, name, email)) { if (email === undefined) { phoneBook[phone] = [phone, name]; } else { From da4465e4673eddcf6eb98feb093134c656d50694 Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 29 Oct 2018 17:36:14 +0500 Subject: [PATCH 19/33] something --- phone-book.js | 1 - 1 file changed, 1 deletion(-) diff --git a/phone-book.js b/phone-book.js index 659fd1b1..b8b72aa8 100644 --- a/phone-book.js +++ b/phone-book.js @@ -32,7 +32,6 @@ function trueParam(phone, name) { * @param {String?} email * @returns {Boolean} */ - function add(phone, name, email) { if (!phoneBook[phone] || trueParam(phone, name, email)) { if (email === undefined) { From badf9081bac828440eae9ea0ecbf725a30438959 Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 29 Oct 2018 17:49:47 +0500 Subject: [PATCH 20/33] something --- phone-book.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phone-book.js b/phone-book.js index b8b72aa8..bfabf710 100644 --- a/phone-book.js +++ b/phone-book.js @@ -21,7 +21,7 @@ let phoneBook = {}; function trueParam(phone, name) { var tel = /(^[0-9]{10}$)/; - return (typeof phone === 'string') && (tel.test(phone)) && (name !== '') && + return (typeof phone !== undefined) && (tel.test(phone)) && (name !== '') && (name !== undefined) && (typeof name === 'string'); } @@ -33,7 +33,7 @@ function trueParam(phone, name) { * @returns {Boolean} */ function add(phone, name, email) { - if (!phoneBook[phone] || trueParam(phone, name, email)) { + if (!(phone in phoneBook) && trueParam(phone, name, email)) { if (email === undefined) { phoneBook[phone] = [phone, name]; } else { From 4011397857ccec7e8c3149b1a9bc284661b66a76 Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 1 Nov 2018 16:47:53 +0500 Subject: [PATCH 21/33] changes --- phone-book.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/phone-book.js b/phone-book.js index bfabf710..7e433347 100644 --- a/phone-book.js +++ b/phone-book.js @@ -18,11 +18,11 @@ let phoneBook = {}; * @param {String?} email * @returns {Boolean} */ -function trueParam(phone, name) { +function trueData(phone, name) { var tel = /(^[0-9]{10}$)/; return (typeof phone !== undefined) && (tel.test(phone)) && (name !== '') && - (name !== undefined) && (typeof name === 'string'); + (!name) && (typeof name === 'string'); } /** @@ -33,8 +33,8 @@ function trueParam(phone, name) { * @returns {Boolean} */ function add(phone, name, email) { - if (!(phone in phoneBook) && trueParam(phone, name, email)) { - if (email === undefined) { + if (!(phone in phoneBook) && trueData(phone, name, email)) { + if ((email) && (email !== '')) { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; @@ -55,8 +55,8 @@ function add(phone, name, email) { * @returns {Boolean} */ function update(phone, name, email) { - if (phoneBook[phone] && trueParam(phone, name, email)) { - if (email === undefined) { + if (phoneBook[phone] && trueData(phone, name, email)) { + if ((email) && (email !== '')) { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; @@ -77,7 +77,7 @@ function findAndRemove(query) { if (query === '') { return 0; } - var res; + let res; var count = 0; for (var phone of Object.keys(phoneBook)) { res = matchSearch(phoneBook[phone], query); @@ -94,8 +94,8 @@ function matchSearch(record, query) { if (query === '*') { return record; } - if (record[0].indexOf(query) !== -1 || record[1].indexOf(query) !== -1 || - (record[2] && record[2].indexOf(query) !== -1)) { + if (record[0].includes(query) === true || record[1].includes(query) === true || + (record[2] && record[2].includes(query) === true)) { return record; } @@ -162,8 +162,8 @@ function importFromCsv(csv) { } const newCsv = csv.split('\n'); var count = 0; - for (let value of newCsv) { - let contact = value.split(';'); + for (let line of newCsv) { + let contact = line.split(';'); var phone = contact[1]; var name = contact[0]; var email = contact[2]; From bb8ceb93807028eab8efe31bfcec0be9840d682b Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 1 Nov 2018 16:50:34 +0500 Subject: [PATCH 22/33] changes --- phone-book.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phone-book.js b/phone-book.js index 7e433347..18e0fd5a 100644 --- a/phone-book.js +++ b/phone-book.js @@ -22,7 +22,7 @@ function trueData(phone, name) { var tel = /(^[0-9]{10}$)/; return (typeof phone !== undefined) && (tel.test(phone)) && (name !== '') && - (!name) && (typeof name === 'string'); + (name) && (typeof name === 'string'); } /** From ade0c4516b6d4291cfa4b8b7d8fa82d838575e48 Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 1 Nov 2018 16:53:27 +0500 Subject: [PATCH 23/33] changes --- phone-book.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phone-book.js b/phone-book.js index 18e0fd5a..790521cd 100644 --- a/phone-book.js +++ b/phone-book.js @@ -77,7 +77,7 @@ function findAndRemove(query) { if (query === '') { return 0; } - let res; + var res; var count = 0; for (var phone of Object.keys(phoneBook)) { res = matchSearch(phoneBook[phone], query); From 1c20dca4c269d5dcb22f63dba8a165d3e3b59770 Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 1 Nov 2018 16:56:15 +0500 Subject: [PATCH 24/33] changes --- phone-book.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phone-book.js b/phone-book.js index 790521cd..1e3cd868 100644 --- a/phone-book.js +++ b/phone-book.js @@ -94,8 +94,8 @@ function matchSearch(record, query) { if (query === '*') { return record; } - if (record[0].includes(query) === true || record[1].includes(query) === true || - (record[2] && record[2].includes(query) === true)) { + if (record[0].indexOf(query) !== -1 || record[1].indexOf(query) !== -1 || + (record[2] && record[2].indexOf(query) !== -1)) { return record; } From 813fd16f8d7fe85f8f472f5ca5a1ccebd1a08177 Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 1 Nov 2018 16:58:40 +0500 Subject: [PATCH 25/33] changes --- phone-book.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phone-book.js b/phone-book.js index 1e3cd868..fbd67a53 100644 --- a/phone-book.js +++ b/phone-book.js @@ -34,7 +34,7 @@ function trueData(phone, name) { */ function add(phone, name, email) { if (!(phone in phoneBook) && trueData(phone, name, email)) { - if ((email) && (email !== '')) { + if ((!email) || (email === '')) { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; @@ -56,7 +56,7 @@ function add(phone, name, email) { */ function update(phone, name, email) { if (phoneBook[phone] && trueData(phone, name, email)) { - if ((email) && (email !== '')) { + if ((!email) || (email === '')) { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; From b69c0ba2afa26b91a561341ed88954f3a93ed512 Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 1 Nov 2018 17:03:13 +0500 Subject: [PATCH 26/33] changes --- phone-book.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phone-book.js b/phone-book.js index fbd67a53..cb400178 100644 --- a/phone-book.js +++ b/phone-book.js @@ -94,8 +94,8 @@ function matchSearch(record, query) { if (query === '*') { return record; } - if (record[0].indexOf(query) !== -1 || record[1].indexOf(query) !== -1 || - (record[2] && record[2].indexOf(query) !== -1)) { + if (record[0].includes(query) === true || record[1].includes(query) === true || + (record[2] && record[2].includes(query) === true)) { return record; } From 0316c9bf03c6fe6db1e1fff957872e5448f87a1b Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 5 Nov 2018 12:41:00 +0500 Subject: [PATCH 27/33] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=BE=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phone-book.js b/phone-book.js index bfabf710..6286fd50 100644 --- a/phone-book.js +++ b/phone-book.js @@ -18,10 +18,10 @@ let phoneBook = {}; * @param {String?} email * @returns {Boolean} */ -function trueParam(phone, name) { +function isValidParams(phone, name) { var tel = /(^[0-9]{10}$)/; - return (typeof phone !== undefined) && (tel.test(phone)) && (name !== '') && + return phone && (tel.test(phone)) && (name !== '') && (name !== undefined) && (typeof name === 'string'); } @@ -33,7 +33,7 @@ function trueParam(phone, name) { * @returns {Boolean} */ function add(phone, name, email) { - if (!(phone in phoneBook) && trueParam(phone, name, email)) { + if (!(phone in phoneBook) && isValidParams(phone, name, email)) { if (email === undefined) { phoneBook[phone] = [phone, name]; } else { @@ -55,7 +55,7 @@ function add(phone, name, email) { * @returns {Boolean} */ function update(phone, name, email) { - if (phoneBook[phone] && trueParam(phone, name, email)) { + if (phoneBook[phone] && isValidParams(phone, name, email)) { if (email === undefined) { phoneBook[phone] = [phone, name]; } else { @@ -77,7 +77,7 @@ function findAndRemove(query) { if (query === '') { return 0; } - var res; + let res; var count = 0; for (var phone of Object.keys(phoneBook)) { res = matchSearch(phoneBook[phone], query); From 6cbfd8c10f708f8e46091238991bcb6d7cc772b1 Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 5 Nov 2018 12:42:58 +0500 Subject: [PATCH 28/33] something --- phone-book.js | 1 + 1 file changed, 1 insertion(+) diff --git a/phone-book.js b/phone-book.js index 6286fd50..b322744f 100644 --- a/phone-book.js +++ b/phone-book.js @@ -73,6 +73,7 @@ function update(phone, name, email) { * @param {String} query * @returns {Number} */ + function findAndRemove(query) { if (query === '') { return 0; From 845661b1c10eeaf6490766dd3b858463f84dec6c Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 5 Nov 2018 23:05:05 +0500 Subject: [PATCH 29/33] =?UTF-8?q?=D0=B7=D0=B0=D0=B1=D1=8B=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phone-book.js b/phone-book.js index d470026a..4bc6904b 100644 --- a/phone-book.js +++ b/phone-book.js @@ -22,7 +22,7 @@ function isValidParams(phone, name) { var tel = /(^[0-9]{10}$)/; return phone && (tel.test(phone)) && (name !== '') && - (name !== undefined) && (typeof name === 'string'); + name && (typeof name === 'string'); } /** @@ -34,7 +34,7 @@ function isValidParams(phone, name) { */ function add(phone, name, email) { if (!(phone in phoneBook) && isValidParams(phone, name, email)) { - if (email === undefined) { + if ((email) && (email !== '')) { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; @@ -56,7 +56,7 @@ function add(phone, name, email) { */ function update(phone, name, email) { if (phoneBook[phone] && isValidParams(phone, name, email)) { - if (email === undefined) { + if ((email) && (email !== '')) { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; @@ -165,9 +165,9 @@ function importFromCsv(csv) { var count = 0; for (let line of newCsv) { let contact = line.split(';'); - var phone = contact[1]; - var name = contact[0]; - var email = contact[2]; + let phone = contact[1]; + let name = contact[0]; + let email = contact[2]; if (add(phone, name, email) || update(phone, name, email)) { count++; } From eae35db08b8c30f9d75170c031472670668888e1 Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 5 Nov 2018 23:08:57 +0500 Subject: [PATCH 30/33] =?UTF-8?q?=D0=B7=D0=B0=D0=B1=D1=8B=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/phone-book.js b/phone-book.js index 4bc6904b..d7b45793 100644 --- a/phone-book.js +++ b/phone-book.js @@ -34,7 +34,7 @@ function isValidParams(phone, name) { */ function add(phone, name, email) { if (!(phone in phoneBook) && isValidParams(phone, name, email)) { - if ((email) && (email !== '')) { + if ((email) || (email !== '')) { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; @@ -56,7 +56,7 @@ function add(phone, name, email) { */ function update(phone, name, email) { if (phoneBook[phone] && isValidParams(phone, name, email)) { - if ((email) && (email !== '')) { + if ((email) || (email !== '')) { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; @@ -82,7 +82,7 @@ function findAndRemove(query) { var count = 0; for (var phone of Object.keys(phoneBook)) { res = matchSearch(phoneBook[phone], query); - if (res !== undefined) { + if (res) { delete phoneBook[phone]; count++; } @@ -114,11 +114,11 @@ function find(query) { const result = []; var res; for (var phone of Object.keys(phoneBook)) { - if (phoneBook[phone] === undefined) { + if (!phoneBook[phone]) { return []; } res = matchSearch(phoneBook[phone], query); - if (res !== undefined) { + if (res) { result.push(res); } } @@ -135,10 +135,10 @@ function newNumber(phone) { function view(result) { var recordSought = []; for (let info of result) { - if (info === undefined) { + if (!info) { return []; } - if (info[2] !== undefined) { + if (info[2]) { recordSought.push(info[1] + ', ' + newNumber(info[0]) + ', ' + info[2]); } else { recordSought.push(info[1] + ', ' + newNumber(info[0])); @@ -158,16 +158,16 @@ function importFromCsv(csv) { // Парсим csv // Добавляем в телефонную книгу // Либо обновляем, если запись с таким телефоном уже существует - if (csv === undefined || csv === '') { + if (!csv || csv === '') { return 0; } const newCsv = csv.split('\n'); var count = 0; for (let line of newCsv) { let contact = line.split(';'); - let phone = contact[1]; - let name = contact[0]; - let email = contact[2]; + var phone = contact[1]; + var name = contact[0]; + var email = contact[2]; if (add(phone, name, email) || update(phone, name, email)) { count++; } From dca7ec7cac4e837d64db80b4ede7e4c5e6a2a03c Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 5 Nov 2018 23:12:53 +0500 Subject: [PATCH 31/33] =?UTF-8?q?=D0=B7=D0=B0=D0=B1=D1=8B=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phone-book.js b/phone-book.js index d7b45793..96a100da 100644 --- a/phone-book.js +++ b/phone-book.js @@ -34,7 +34,7 @@ function isValidParams(phone, name) { */ function add(phone, name, email) { if (!(phone in phoneBook) && isValidParams(phone, name, email)) { - if ((email) || (email !== '')) { + if ((!email) || (email !== '')) { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; @@ -56,7 +56,7 @@ function add(phone, name, email) { */ function update(phone, name, email) { if (phoneBook[phone] && isValidParams(phone, name, email)) { - if ((email) || (email !== '')) { + if ((!email) || (email !== '')) { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; From 37cdc9057cbed37d6c1600571fd03244b82a3491 Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 5 Nov 2018 23:14:58 +0500 Subject: [PATCH 32/33] =?UTF-8?q?=D0=B7=D0=B0=D0=B1=D1=8F=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D1=83=D1=82=D0=B0=D0=BB=D0=B0=D0=B0=D0=B0=D1=81=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phone-book.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phone-book.js b/phone-book.js index 96a100da..3fc8f843 100644 --- a/phone-book.js +++ b/phone-book.js @@ -34,7 +34,7 @@ function isValidParams(phone, name) { */ function add(phone, name, email) { if (!(phone in phoneBook) && isValidParams(phone, name, email)) { - if ((!email) || (email !== '')) { + if (!email || (email === '')) { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; @@ -56,7 +56,7 @@ function add(phone, name, email) { */ function update(phone, name, email) { if (phoneBook[phone] && isValidParams(phone, name, email)) { - if ((!email) || (email !== '')) { + if (!email || (email === '')) { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; From 8c543f3f7c2975dbfc5a4e64487811da113a0f0d Mon Sep 17 00:00:00 2001 From: Veronica Date: Sun, 11 Nov 2018 20:38:33 +0500 Subject: [PATCH 33/33] task --- phone-book.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/phone-book.js b/phone-book.js index 3fc8f843..d8eedb44 100644 --- a/phone-book.js +++ b/phone-book.js @@ -21,8 +21,8 @@ let phoneBook = {}; function isValidParams(phone, name) { var tel = /(^[0-9]{10}$)/; - return phone && (tel.test(phone)) && (name !== '') && - name && (typeof name === 'string'); + return phone && tel.test(phone) && + name && typeof name === 'string'; } /** @@ -34,7 +34,7 @@ function isValidParams(phone, name) { */ function add(phone, name, email) { if (!(phone in phoneBook) && isValidParams(phone, name, email)) { - if (!email || (email === '')) { + if (!email || email === '') { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; @@ -56,7 +56,7 @@ function add(phone, name, email) { */ function update(phone, name, email) { if (phoneBook[phone] && isValidParams(phone, name, email)) { - if (!email || (email === '')) { + if (!email || email === '') { phoneBook[phone] = [phone, name]; } else { phoneBook[phone] = [phone, name, email]; @@ -79,8 +79,8 @@ function findAndRemove(query) { return 0; } let res; - var count = 0; - for (var phone of Object.keys(phoneBook)) { + let count = 0; + for (const phone of Object.keys(phoneBook)) { res = matchSearch(phoneBook[phone], query); if (res) { delete phoneBook[phone]; @@ -112,7 +112,7 @@ function find(query) { return []; } const result = []; - var res; + let res; for (var phone of Object.keys(phoneBook)) { if (!phoneBook[phone]) { return []; @@ -133,7 +133,7 @@ function newNumber(phone) { } function view(result) { - var recordSought = []; + const recordSought = []; for (let info of result) { if (!info) { return []; @@ -162,7 +162,7 @@ function importFromCsv(csv) { return 0; } const newCsv = csv.split('\n'); - var count = 0; + let count = 0; for (let line of newCsv) { let contact = line.split(';'); var phone = contact[1];