{"action":"created","comment":{"url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/pulls/comments/43322304","id":43322304,"diff_hunk":"@@ -1,4 +1,158 @@\n 'use strict';\n \n module.exports.get = function (collection, startPoint, depth) {\n+    var index = 0;\n+    var data = getInvitedFriends(collection, startPoint, depth);\n+    var length = data.length;\n+    var currentName = startPoint;\n+    return {\n+        next: function (name) {\n+            if (collection[startPoint] === undefined) {\n+                return null;\n+            }\n+            this.checkChanges();\n+            var element;\n+            if (!this.hasNext() || !this.hasName(name) || startPoint === undefined ||\n+                collection[startPoint] === undefined) {\n+                return null;\n+            }\n+            while (this.hasNext()) {\n+                element = data[index];\n+                if (element.name === name || name === undefined) {\n+                    index += 1;\n+                    currentName = element.name;\n+                    var res = {\n+                        name: element.name,\n+                        phone: element.contactInfo.phone\n+                    };\n+                    return res;\n+                }\n+                index += 1;\n+                currentName = element.name;\n+            }\n+            return null;\n+        },\n+        prev: function () {\n+            this.checkChanges();\n+            var element;\n+            if (!this.hasPrev() || startPoint === undefined) {\n+                return null;\n+            }\n+            element = data[index - 2];\n+            currentName = element.name;\n+            index -= 1;\n+            var res = {\n+                name: element.name,\n+                phone: element.contactInfo.phone\n+            };\n+            return res;\n+        },\n+        hasName: function (name) {\n+            if (name != undefined) {\n+                return data.some(contact => contact.name === name);\n+            }\n+            return true;\n+        },\n+        hasNext: function () {\n+            return index < length;\n+        },\n+        hasPrev: function () {\n+            return index > 1;\n+        },\n+        nextMale: function () {\n+            return this.getMale(1, 0, this.hasNext);\n+        },\n+        prevMale: function () {\n+            return this.getMale(-1, 2, this.hasPrev);\n+        },\n+        getMale: function (direction, step, func) {\n+            var element;\n+            this.checkChanges();\n+            while (func()) {\n+                element = data[index - step];\n+                if (element.contactInfo.gender === 'Мужской') {\n+                    index += 1 * direction;\n+                    currentName = element.name;\n+                    var res = {\n+                        name: element.name,\n+                        phone: element.contactInfo.phone\n+                    };\n+                    return res;\n+                }\n+                index += 1 * direction;\n+                currentName = element.name;\n+            }\n+            return null;\n+        },\n+        checkChanges: function () {\n+            if (collectionLength != Object.keys(collection).length) {\n+                data = getInvitedFriends(collection, startPoint, depth);\n+                length = data.length;\n+                this.findIndex();\n+            }\n+        },\n+        findIndex: function () {\n+            if (data.some(contact => contact.name === currentName)) {\n+                for (var i = 0; i < data.length; i++) {\n+                    if (data[i].name === currentName) {\n+                        index = i;\n+                    }\n+                }\n+            }\n+        }\n+    };\n };\n+\n+var collectionLength;\n+\n+function getInvitedFriends(collection, startPoint, depth) {\n+    collectionLength = Object.keys(collection).length;\n+    var invitedFriends = [];\n+    if (collection[startPoint] === undefined) {\n+        return invitedFriends;\n+    }\n+    var queue = [startPoint];\n+    var toStop = false;\n+    var i = 0;\n+    while (!toStop) {\n+        var foundFriends = [];\n+        while (queue.length != 0) {\n+            var currentFriend = queue.shift();\n+            if (collection[currentFriend] != undefined) {\n+                //получили всех друзей\n+                var friends = collection[currentFriend].friends.slice();\n+                /*оставили только тех, кто ещё не встречался, не был удалён,\n+                не является организатором*/\n+                friends = friends.filter(function (friend) {\n+                    return !(invitedFriends.some(contact => contact.name === friend) ||\n+                        (foundFriends.some(contact => contact.name === friend)) ||\n+                        startPoint === friend ||\n+                        Object.keys(collection).indexOf(friend) === -1);\n+                });\n+                //отсортировали\n+                friends = friends.sort(function (a, b) {\n+                    return a > b ? 1 : -1;\n+                });\n+                //добавили в итоговый список, указывая имена как поле\n+                friends.forEach(function (friend) {\n+                    var newContact = {\n+                        name: friend,\n+                        contactInfo: collection[friend]\n+                    };\n+                    foundFriends.push(newContact);\n+                });\n+            }\n+        }\n+        //останавливаем поиск, если друзей больше не можем найти или достигнута depth","path":"iterator.js","position":146,"original_position":146,"commit_id":"4af3efe24183e0d55f90dfa9bd0bfaf7cdd3ddc2","original_commit_id":"4af3efe24183e0d55f90dfa9bd0bfaf7cdd3ddc2","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":"Комментарий (если он вообще нужен) должен описывать почему что-то происходит, а не что происходит.\r\n\r\nВ строчке ниже содержится та же информация, что и в этом комментарии. ","created_at":"2015-10-28T21:41:17Z","updated_at":"2015-10-28T21:41:17Z","html_url":"https://github.com/urfu-2015/javascript-tasks-4/pull/11#discussion_r43322304","pull_request_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/pulls/comments/43322304"},"html":{"href":"https://github.com/urfu-2015/javascript-tasks-4/pull/11#discussion_r43322304"},"pull_request":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/pulls/11","id":48654309,"html_url":"https://github.com/urfu-2015/javascript-tasks-4/pull/11","diff_url":"https://github.com/urfu-2015/javascript-tasks-4/pull/11.diff","patch_url":"https://github.com/urfu-2015/javascript-tasks-4/pull/11.patch","issue_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/issues/11","number":11,"state":"open","locked":false,"title":"Онуфриенко Екатерина","user":{"login":"onufrienko","id":14929766,"avatar_url":"https://avatars.githubusercontent.com/u/14929766?v=3","gravatar_id":"","url":"https://api.github.com/users/onufrienko","html_url":"https://github.com/onufrienko","followers_url":"https://api.github.com/users/onufrienko/followers","following_url":"https://api.github.com/users/onufrienko/following{/other_user}","gists_url":"https://api.github.com/users/onufrienko/gists{/gist_id}","starred_url":"https://api.github.com/users/onufrienko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onufrienko/subscriptions","organizations_url":"https://api.github.com/users/onufrienko/orgs","repos_url":"https://api.github.com/users/onufrienko/repos","events_url":"https://api.github.com/users/onufrienko/events{/privacy}","received_events_url":"https://api.github.com/users/onufrienko/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-24T11:38:48Z","updated_at":"2015-10-28T21:41:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e1e75f4a13b6b435d782943ba9c33873454d6bd6","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-4/pulls/11/commits","review_comments_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/pulls/11/comments","review_comment_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/pulls/comments{/number}","comments_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/issues/11/comments","statuses_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/statuses/4af3efe24183e0d55f90dfa9bd0bfaf7cdd3ddc2","head":{"label":"onufrienko:master","ref":"master","sha":"4af3efe24183e0d55f90dfa9bd0bfaf7cdd3ddc2","user":{"login":"onufrienko","id":14929766,"avatar_url":"https://avatars.githubusercontent.com/u/14929766?v=3","gravatar_id":"","url":"https://api.github.com/users/onufrienko","html_url":"https://github.com/onufrienko","followers_url":"https://api.github.com/users/onufrienko/followers","following_url":"https://api.github.com/users/onufrienko/following{/other_user}","gists_url":"https://api.github.com/users/onufrienko/gists{/gist_id}","starred_url":"https://api.github.com/users/onufrienko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onufrienko/subscriptions","organizations_url":"https://api.github.com/users/onufrienko/orgs","repos_url":"https://api.github.com/users/onufrienko/repos","events_url":"https://api.github.com/users/onufrienko/events{/privacy}","received_events_url":"https://api.github.com/users/onufrienko/received_events","type":"User","site_admin":false},"repo":{"id":44863459,"name":"javascript-tasks-4","full_name":"onufrienko/javascript-tasks-4","owner":{"login":"onufrienko","id":14929766,"avatar_url":"https://avatars.githubusercontent.com/u/14929766?v=3","gravatar_id":"","url":"https://api.github.com/users/onufrienko","html_url":"https://github.com/onufrienko","followers_url":"https://api.github.com/users/onufrienko/followers","following_url":"https://api.github.com/users/onufrienko/following{/other_user}","gists_url":"https://api.github.com/users/onufrienko/gists{/gist_id}","starred_url":"https://api.github.com/users/onufrienko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onufrienko/subscriptions","organizations_url":"https://api.github.com/users/onufrienko/orgs","repos_url":"https://api.github.com/users/onufrienko/repos","events_url":"https://api.github.com/users/onufrienko/events{/privacy}","received_events_url":"https://api.github.com/users/onufrienko/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/onufrienko/javascript-tasks-4","description":"Задача к лекции «Замыкания в Javascript» – «Мальчишник в Вегасе»","fork":true,"url":"https://api.github.com/repos/onufrienko/javascript-tasks-4","forks_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/forks","keys_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/teams","hooks_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/hooks","issue_events_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/issues/events{/number}","events_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/events","assignees_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/assignees{/user}","branches_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/branches{/branch}","tags_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/tags","blobs_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/git/refs{/sha}","trees_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/statuses/{sha}","languages_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/languages","stargazers_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/stargazers","contributors_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/contributors","subscribers_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/subscribers","subscription_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/subscription","commits_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/commits{/sha}","git_commits_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/git/commits{/sha}","comments_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/comments{/number}","issue_comment_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/issues/comments{/number}","contents_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/contents/{+path}","compare_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/merges","archive_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/downloads","issues_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/issues{/number}","pulls_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/pulls{/number}","milestones_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/milestones{/number}","notifications_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/labels{/name}","releases_url":"https://api.github.com/repos/onufrienko/javascript-tasks-4/releases{/id}","created_at":"2015-10-24T11:37:19Z","updated_at":"2015-10-24T11:37:20Z","pushed_at":"2015-10-26T16:31:40Z","git_url":"git://github.com/onufrienko/javascript-tasks-4.git","ssh_url":"git@github.com:onufrienko/javascript-tasks-4.git","clone_url":"https://github.com/onufrienko/javascript-tasks-4.git","svn_url":"https://github.com/onufrienko/javascript-tasks-4","homepage":"","size":120,"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":"6125978146eec1796f87a724228d8278a4aa66f6","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":44542271,"name":"javascript-tasks-4","full_name":"urfu-2015/javascript-tasks-4","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-4","description":"Задача к лекции «Замыкания в Javascript» – «Мальчишник в Вегасе»","fork":false,"url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4","forks_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/forks","keys_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/teams","hooks_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/hooks","issue_events_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/issues/events{/number}","events_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/events","assignees_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/assignees{/user}","branches_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/branches{/branch}","tags_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/tags","blobs_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/git/refs{/sha}","trees_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/statuses/{sha}","languages_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/languages","stargazers_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/stargazers","contributors_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/contributors","subscribers_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/subscribers","subscription_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/subscription","commits_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/commits{/sha}","git_commits_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/git/commits{/sha}","comments_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/comments{/number}","issue_comment_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/issues/comments{/number}","contents_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/contents/{+path}","compare_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/merges","archive_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/downloads","issues_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/issues{/number}","pulls_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/pulls{/number}","milestones_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/milestones{/number}","notifications_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/labels{/name}","releases_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/releases{/id}","created_at":"2015-10-19T14:57:11Z","updated_at":"2015-10-20T18:57:43Z","pushed_at":"2015-10-28T19:10:08Z","git_url":"git://github.com/urfu-2015/javascript-tasks-4.git","ssh_url":"git@github.com:urfu-2015/javascript-tasks-4.git","clone_url":"https://github.com/urfu-2015/javascript-tasks-4.git","svn_url":"https://github.com/urfu-2015/javascript-tasks-4","homepage":"","size":1471,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":61,"mirror_url":null,"open_issues_count":42,"forks":61,"open_issues":42,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/pulls/11"},"html":{"href":"https://github.com/urfu-2015/javascript-tasks-4/pull/11"},"issue":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/issues/11"},"comments":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-4/statuses/4af3efe24183e0d55f90dfa9bd0bfaf7cdd3ddc2"}}}}