{"action":"created","comment":{"url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls/comments/41561966","id":41561966,"diff_hunk":"@@ -1,52 +1,130 @@\n 'use strict';\n+Object.values = obj => Object.keys(obj).map(key => obj[key]);\n+var phoneRegExp = /^(\\+?\\d{1,2})?\\s?(\\(\\d{3}\\)|\\d{3})\\s?\\d{3}(\\-\\d\\-|\\s\\d\\s|\\d)\\d{3}$/;\n+var emailRegExp = /^([a-z0-9._-])*@([a-zа-я0-9_-]+\\.)+([a-zа-я]+)$/;\n+var phoneBook = {};\n \n-var phoneBook; // Здесь вы храните записи как хотите\n+function isPhoneValid(phone) {\n+    return phoneRegExp.test(phone);\n+}\n \n-/*\n-   Функция добавления записи в телефонную книгу.\n-   На вход может прийти что угодно, будьте осторожны.\n-*/\n-module.exports.add = function add(name, phone, email) {\n+function isEmailValid(email) {\n \n-    // Ваша невероятная магия здесь\n+    return emailRegExp.test(email);\n+}\n \n+module.exports.add = function add(name, phone, email) {\n+    if (!(typeof name === 'string' && typeof phone === 'string' && typeof email === 'string')) {\n+        return;\n+    }\n+    var lowerEmail = email.toLocaleLowerCase();\n+    var key = [name, phone, email].join(' ');\n+    if (isPhoneValid(phone) && isEmailValid(lowerEmail)) {\n+        phoneBook[key] = {name: name, phone: phone, email: email};\n+    }\n };\n \n-/*\n-   Функция поиска записи в телефонную книгу.\n-   Поиск ведется по всем полям.\n-*/\n module.exports.find = function find(query) {\n-\n-    // Ваша удивительная магия здесь\n-\n+    if (query) {\n+        Object.values(phoneBook).forEach(function (record) {\n+            var found = false;\n+            Object.keys(record).forEach(function (key) {\n+                if (found) {\n+                    return;\n+                }\n+                if (record[key].includes(query)) {\n+                    console.log([record.name, record.phone, record.email].join(', '));\n+                    found = true;\n+                }\n+            });\n+        });\n+    } else {\n+        Object.values(phoneBook).forEach(function (record) {\n+            console.log([record.name, record.phone, record.email].join(', '));\n+        });\n+    }\n };\n \n-/*\n-   Функция удаления записи в телефонной книге.\n-*/\n module.exports.remove = function remove(query) {\n-\n-    // Ваша необьяснимая магия здесь\n-\n+    var removedContacts = 0;\n+    Object.keys(phoneBook).forEach(function (recordKey) {\n+        var removed = false;\n+        var record = phoneBook[recordKey];\n+        Object.keys(record).forEach(function (key) {\n+            if (!removed && record[key].includes(query)) {\n+                delete phoneBook[recordKey];\n+                removedContacts++;\n+            };\n+        });\n+    });\n+    if (removedContacts === 1) {\n+        console.log('Removed 1 contact');\n+    } else {\n+        if (removedContacts > 0) {\n+            console.log('Removed ' + removedContacts + ' contacts');\n+        } else {\n+            console.log('No contact wasn\\'t removed');\n+        }\n+    }\n };\n \n-/*\n-   Функция импорта записей из файла (задача со звёздочкой!).\n-*/\n module.exports.importFromCsv = function importFromCsv(filename) {\n     var data = require('fs').readFileSync(filename, 'utf-8');\n-\n-    // Ваша чёрная магия:\n-    // - Разбираете записи из `data`\n-    // - Добавляете каждую запись в книгу\n+    data.split('\\r\\n').forEach(function (line) {\n+        var splittedLine = line.split(';');\n+        module.exports.add(splittedLine[0], splittedLine[1], splittedLine[2]);\n+    });\n };\n \n-/*\n-   Функция вывода всех телефонов в виде ASCII (задача со звёздочкой!).\n-*/\n-module.exports.showTable = function showTable(filename) {\n+String.prototype.repeat = function (n) {\n+    var r = '';\n+    if (typeof n == 'number') {\n+        for (var i = 1; i <= n; i++) {\n+            r += this;\n+        }\n+    }\n+    return r;\n+};\n \n-    // Ваша чёрная магия здесь\n+function getPrintLineFunction(maxNameLength, maxPhoneLength, maxEmailLength) {\n+    return function (first, second, third) {","path":"phoneBook.js","position":122,"original_position":122,"commit_id":"c9c60a9a43acb208700435e5322c1037272690a3","original_commit_id":"c9c60a9a43acb208700435e5322c1037272690a3","user":{"login":"sameoldmadness","id":1537724,"avatar_url":"https://avatars.githubusercontent.com/u/1537724?v=3","gravatar_id":"","url":"https://api.github.com/users/sameoldmadness","html_url":"https://github.com/sameoldmadness","followers_url":"https://api.github.com/users/sameoldmadness/followers","following_url":"https://api.github.com/users/sameoldmadness/following{/other_user}","gists_url":"https://api.github.com/users/sameoldmadness/gists{/gist_id}","starred_url":"https://api.github.com/users/sameoldmadness/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sameoldmadness/subscriptions","organizations_url":"https://api.github.com/users/sameoldmadness/orgs","repos_url":"https://api.github.com/users/sameoldmadness/repos","events_url":"https://api.github.com/users/sameoldmadness/events{/privacy}","received_events_url":"https://api.github.com/users/sameoldmadness/received_events","type":"User","site_admin":false},"body":"Тут надо бы у обеих функций либо first-second-third, либо name-phone-length.","created_at":"2015-10-08T20:08:30Z","updated_at":"2015-10-08T20:08:30Z","html_url":"https://github.com/urfu-2015/javascript-tasks-2/pull/6#discussion_r41561966","pull_request_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls/comments/41561966"},"html":{"href":"https://github.com/urfu-2015/javascript-tasks-2/pull/6#discussion_r41561966"},"pull_request":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls/6","id":47068107,"html_url":"https://github.com/urfu-2015/javascript-tasks-2/pull/6","diff_url":"https://github.com/urfu-2015/javascript-tasks-2/pull/6.diff","patch_url":"https://github.com/urfu-2015/javascript-tasks-2/pull/6.patch","issue_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/issues/6","number":6,"state":"open","locked":false,"title":"Mironov Alexey","user":{"login":"mironov-alexey","id":6783167,"avatar_url":"https://avatars.githubusercontent.com/u/6783167?v=3","gravatar_id":"","url":"https://api.github.com/users/mironov-alexey","html_url":"https://github.com/mironov-alexey","followers_url":"https://api.github.com/users/mironov-alexey/followers","following_url":"https://api.github.com/users/mironov-alexey/following{/other_user}","gists_url":"https://api.github.com/users/mironov-alexey/gists{/gist_id}","starred_url":"https://api.github.com/users/mironov-alexey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mironov-alexey/subscriptions","organizations_url":"https://api.github.com/users/mironov-alexey/orgs","repos_url":"https://api.github.com/users/mironov-alexey/repos","events_url":"https://api.github.com/users/mironov-alexey/events{/privacy}","received_events_url":"https://api.github.com/users/mironov-alexey/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-07T19:04:00Z","updated_at":"2015-10-08T20:08:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"25757cde529f754227ed5b3727e421c886e15e65","assignee":{"login":"sameoldmadness","id":1537724,"avatar_url":"https://avatars.githubusercontent.com/u/1537724?v=3","gravatar_id":"","url":"https://api.github.com/users/sameoldmadness","html_url":"https://github.com/sameoldmadness","followers_url":"https://api.github.com/users/sameoldmadness/followers","following_url":"https://api.github.com/users/sameoldmadness/following{/other_user}","gists_url":"https://api.github.com/users/sameoldmadness/gists{/gist_id}","starred_url":"https://api.github.com/users/sameoldmadness/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sameoldmadness/subscriptions","organizations_url":"https://api.github.com/users/sameoldmadness/orgs","repos_url":"https://api.github.com/users/sameoldmadness/repos","events_url":"https://api.github.com/users/sameoldmadness/events{/privacy}","received_events_url":"https://api.github.com/users/sameoldmadness/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls/6/commits","review_comments_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls/6/comments","review_comment_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/issues/6/comments","statuses_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/statuses/c9c60a9a43acb208700435e5322c1037272690a3","head":{"label":"mironov-alexey:master","ref":"master","sha":"c9c60a9a43acb208700435e5322c1037272690a3","user":{"login":"mironov-alexey","id":6783167,"avatar_url":"https://avatars.githubusercontent.com/u/6783167?v=3","gravatar_id":"","url":"https://api.github.com/users/mironov-alexey","html_url":"https://github.com/mironov-alexey","followers_url":"https://api.github.com/users/mironov-alexey/followers","following_url":"https://api.github.com/users/mironov-alexey/following{/other_user}","gists_url":"https://api.github.com/users/mironov-alexey/gists{/gist_id}","starred_url":"https://api.github.com/users/mironov-alexey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mironov-alexey/subscriptions","organizations_url":"https://api.github.com/users/mironov-alexey/orgs","repos_url":"https://api.github.com/users/mironov-alexey/repos","events_url":"https://api.github.com/users/mironov-alexey/events{/privacy}","received_events_url":"https://api.github.com/users/mironov-alexey/received_events","type":"User","site_admin":false},"repo":{"id":43812972,"name":"javascript-tasks-2","full_name":"mironov-alexey/javascript-tasks-2","owner":{"login":"mironov-alexey","id":6783167,"avatar_url":"https://avatars.githubusercontent.com/u/6783167?v=3","gravatar_id":"","url":"https://api.github.com/users/mironov-alexey","html_url":"https://github.com/mironov-alexey","followers_url":"https://api.github.com/users/mironov-alexey/followers","following_url":"https://api.github.com/users/mironov-alexey/following{/other_user}","gists_url":"https://api.github.com/users/mironov-alexey/gists{/gist_id}","starred_url":"https://api.github.com/users/mironov-alexey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mironov-alexey/subscriptions","organizations_url":"https://api.github.com/users/mironov-alexey/orgs","repos_url":"https://api.github.com/users/mironov-alexey/repos","events_url":"https://api.github.com/users/mironov-alexey/events{/privacy}","received_events_url":"https://api.github.com/users/mironov-alexey/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mironov-alexey/javascript-tasks-2","description":"Задача к лекции «Основы Javascript» – «Телефонная книга»","fork":true,"url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2","forks_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/forks","keys_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/teams","hooks_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/hooks","issue_events_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/issues/events{/number}","events_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/events","assignees_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/assignees{/user}","branches_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/branches{/branch}","tags_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/tags","blobs_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/git/refs{/sha}","trees_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/statuses/{sha}","languages_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/languages","stargazers_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/stargazers","contributors_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/contributors","subscribers_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/subscribers","subscription_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/subscription","commits_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/commits{/sha}","git_commits_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/git/commits{/sha}","comments_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/comments{/number}","issue_comment_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/issues/comments{/number}","contents_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/contents/{+path}","compare_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/merges","archive_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/downloads","issues_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/issues{/number}","pulls_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/pulls{/number}","milestones_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/milestones{/number}","notifications_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/labels{/name}","releases_url":"https://api.github.com/repos/mironov-alexey/javascript-tasks-2/releases{/id}","created_at":"2015-10-07T12:04:37Z","updated_at":"2015-10-07T12:04:38Z","pushed_at":"2015-10-07T19:40:58Z","git_url":"git://github.com/mironov-alexey/javascript-tasks-2.git","ssh_url":"git@github.com:mironov-alexey/javascript-tasks-2.git","clone_url":"https://github.com/mironov-alexey/javascript-tasks-2.git","svn_url":"https://github.com/mironov-alexey/javascript-tasks-2","homepage":"","size":94,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"urfu-2015:master","ref":"master","sha":"bea201db13813c362127a099bd509bb41817b05d","user":{"login":"urfu-2015","id":14800971,"avatar_url":"https://avatars.githubusercontent.com/u/14800971?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2015","html_url":"https://github.com/urfu-2015","followers_url":"https://api.github.com/users/urfu-2015/followers","following_url":"https://api.github.com/users/urfu-2015/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2015/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2015/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2015/subscriptions","organizations_url":"https://api.github.com/users/urfu-2015/orgs","repos_url":"https://api.github.com/users/urfu-2015/repos","events_url":"https://api.github.com/users/urfu-2015/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2015/received_events","type":"Organization","site_admin":false},"repo":{"id":43743710,"name":"javascript-tasks-2","full_name":"urfu-2015/javascript-tasks-2","owner":{"login":"urfu-2015","id":14800971,"avatar_url":"https://avatars.githubusercontent.com/u/14800971?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2015","html_url":"https://github.com/urfu-2015","followers_url":"https://api.github.com/users/urfu-2015/followers","following_url":"https://api.github.com/users/urfu-2015/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2015/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2015/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2015/subscriptions","organizations_url":"https://api.github.com/users/urfu-2015/orgs","repos_url":"https://api.github.com/users/urfu-2015/repos","events_url":"https://api.github.com/users/urfu-2015/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2015/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/urfu-2015/javascript-tasks-2","description":"Задача к лекции «Основы Javascript» – «Телефонная книга»","fork":false,"url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2","forks_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/forks","keys_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/teams","hooks_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/hooks","issue_events_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/issues/events{/number}","events_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/events","assignees_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/assignees{/user}","branches_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/branches{/branch}","tags_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/tags","blobs_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/git/refs{/sha}","trees_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/statuses/{sha}","languages_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/languages","stargazers_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/stargazers","contributors_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/contributors","subscribers_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/subscribers","subscription_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/subscription","commits_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/commits{/sha}","git_commits_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/git/commits{/sha}","comments_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/comments{/number}","issue_comment_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/issues/comments{/number}","contents_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/contents/{+path}","compare_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/merges","archive_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/downloads","issues_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/issues{/number}","pulls_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls{/number}","milestones_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/milestones{/number}","notifications_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/labels{/name}","releases_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/releases{/id}","created_at":"2015-10-06T10:22:05Z","updated_at":"2015-10-08T14:08:53Z","pushed_at":"2015-10-08T19:01:33Z","git_url":"git://github.com/urfu-2015/javascript-tasks-2.git","ssh_url":"git@github.com:urfu-2015/javascript-tasks-2.git","clone_url":"https://github.com/urfu-2015/javascript-tasks-2.git","svn_url":"https://github.com/urfu-2015/javascript-tasks-2","homepage":"","size":205,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":46,"mirror_url":null,"open_issues_count":7,"forks":46,"open_issues":7,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls/6"},"html":{"href":"https://github.com/urfu-2015/javascript-tasks-2/pull/6"},"issue":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/issues/6"},"comments":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-2/statuses/c9c60a9a43acb208700435e5322c1037272690a3"}}}}