{"action":"created","comment":{"url":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls/comments/93294683","pull_request_review_id":13815578,"id":93294683,"diff_hunk":"@@ -19,15 +46,154 @@ function Iterator(friends, filter) {\n  * @param {Number} maxLevel – максимальный круг друзей\n  */\n function LimitedIterator(friends, filter, maxLevel) {\n-    console.info(friends, filter, maxLevel);\n+    Iterator.call(this, friends, filter, maxLevel);\n+}\n+LimitedIterator.prototype = Object.create(Iterator.prototype);\n+\n+/**\n+ * Сортирует приглашенных друзей по имени и по уровням\n+ * @param {Object[]} friends\n+ * @param {Number} maxLevel – максимальный круг друзей\n+ * @returns {Object[]}\n+ */\n+function getSortedByNameAndPriorityFriends(friends, maxLevel) {\n+    var priorityGroups = setPriority(friends, maxLevel);\n+    var result = [];\n+    priorityGroups.forEach(function (priorityGroup) {\n+        priorityGroup = priorityGroup.sort(comparer);\n+        result = result.concat(priorityGroup);\n+    });\n+\n+    return result;\n+}\n+\n+/**\n+ * Получает список друзей отсортированных по уровням\n+ * @param {Object[]} friends - исходный массив друзей\n+ * @param {Number} maxLevel – максимальный круг друзей\n+ * @returns {Object[]} resultArray - список друзей\n+ */\n+function setPriority(friends, maxLevel) {\n+    if (maxLevel <= 0) {\n+        return [];\n+    }\n+    var _friends = [];\n+    copyArrays(friends, _friends);\n+    var resultArray = [];\n+    resultArray.push(getFirstLevelFriends(_friends));\n+    var N = 2;\n+    if (maxLevel === 1) {\n+        return resultArray;\n+    }\n+    getOtherLevelFriends(_friends, maxLevel, N, resultArray);\n+\n+    return resultArray;\n+}\n+\n+\n+/**\n+ * Получает список лучщих друзей (1 уровня)\n+ * @param {Object[]} friends - массив друзей,\n+ * которых мы еще не приглашали\n+ * @returns {Object[]} firstLevelFriends - лучшие друзья\n+ */\n+function getFirstLevelFriends(friends) {\n+    var firstLevelFriends = [];\n+    for (var i = 0; i < friends.length; i++) {\n+        if (friends[i].best === true) {\n+            firstLevelFriends.push(friends[i]);\n+            friends.splice(i, 1);\n+            i--;\n+        }\n+    }\n+\n+    return firstLevelFriends;\n+}\n+\n+/**\n+ * Получает списки остальных друзей\n+ * @param {Object[]} friends - массив друзей,\n+ * которых мы еще не приглашали\n+ * @param {Number} maxLevel – максимальный круг друзей\n+ * @param {Number} N - номер текущего уровня\n+ * @param {Object[]} resultArray – массив, который содержит массивы друзей одного уровня\n+ */\n+function getOtherLevelFriends(friends, maxLevel, N, resultArray) {\n+    while (friends.length !== 0) {\n+        var start = friends.length;\n+        var NlevelFriends = [];\n+        for (var q = 0; q < resultArray[N - 2].length; q++) {\n+            var result = getNlevelFriends(friends, resultArray[N - 2][q]);\n+            NlevelFriends = NlevelFriends.concat(result);\n+        }\n+        resultArray.push(NlevelFriends);\n+        N++;\n+        if (friends.length - start === 0) {\n+            break;\n+        }\n+        if (maxLevel !== undefined && maxLevel === N - 1) {","path":"lib.js","position":126,"original_position":126,"commit_id":"5816a02ccb47d47e8e7b116d3ba900db55e3da70","original_commit_id":"15cfde029d157ac147a0e7767952612b18c8aa44","user":{"login":"evilj0e","id":914429,"avatar_url":"https://avatars.githubusercontent.com/u/914429?v=3","gravatar_id":"","url":"https://api.github.com/users/evilj0e","html_url":"https://github.com/evilj0e","followers_url":"https://api.github.com/users/evilj0e/followers","following_url":"https://api.github.com/users/evilj0e/following{/other_user}","gists_url":"https://api.github.com/users/evilj0e/gists{/gist_id}","starred_url":"https://api.github.com/users/evilj0e/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evilj0e/subscriptions","organizations_url":"https://api.github.com/users/evilj0e/orgs","repos_url":"https://api.github.com/users/evilj0e/repos","events_url":"https://api.github.com/users/evilj0e/events{/privacy}","received_events_url":"https://api.github.com/users/evilj0e/received_events","type":"User","site_admin":false},"body":"Это лучше выносить во флаги","created_at":"2016-12-20T18:19:59Z","updated_at":"2016-12-20T18:23:05Z","html_url":"https://github.com/urfu-2016/javascript-task-7/pull/34#discussion_r93294683","pull_request_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls/34","_links":{"self":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls/comments/93294683"},"html":{"href":"https://github.com/urfu-2016/javascript-task-7/pull/34#discussion_r93294683"},"pull_request":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls/34"}}},"pull_request":{"url":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls/34","id":95077610,"html_url":"https://github.com/urfu-2016/javascript-task-7/pull/34","diff_url":"https://github.com/urfu-2016/javascript-task-7/pull/34.diff","patch_url":"https://github.com/urfu-2016/javascript-task-7/pull/34.patch","issue_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/issues/34","number":34,"state":"open","locked":false,"title":"Ермаков Степан","user":{"login":"predatorfromekb","id":11776751,"avatar_url":"https://avatars.githubusercontent.com/u/11776751?v=3","gravatar_id":"","url":"https://api.github.com/users/predatorfromekb","html_url":"https://github.com/predatorfromekb","followers_url":"https://api.github.com/users/predatorfromekb/followers","following_url":"https://api.github.com/users/predatorfromekb/following{/other_user}","gists_url":"https://api.github.com/users/predatorfromekb/gists{/gist_id}","starred_url":"https://api.github.com/users/predatorfromekb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/predatorfromekb/subscriptions","organizations_url":"https://api.github.com/users/predatorfromekb/orgs","repos_url":"https://api.github.com/users/predatorfromekb/repos","events_url":"https://api.github.com/users/predatorfromekb/events{/privacy}","received_events_url":"https://api.github.com/users/predatorfromekb/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-11-23T20:52:01Z","updated_at":"2016-12-20T18:23:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9b16d9682e3dc23d0a35be42ecf3806875a5211a","assignee":{"login":"evilj0e","id":914429,"avatar_url":"https://avatars.githubusercontent.com/u/914429?v=3","gravatar_id":"","url":"https://api.github.com/users/evilj0e","html_url":"https://github.com/evilj0e","followers_url":"https://api.github.com/users/evilj0e/followers","following_url":"https://api.github.com/users/evilj0e/following{/other_user}","gists_url":"https://api.github.com/users/evilj0e/gists{/gist_id}","starred_url":"https://api.github.com/users/evilj0e/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evilj0e/subscriptions","organizations_url":"https://api.github.com/users/evilj0e/orgs","repos_url":"https://api.github.com/users/evilj0e/repos","events_url":"https://api.github.com/users/evilj0e/events{/privacy}","received_events_url":"https://api.github.com/users/evilj0e/received_events","type":"User","site_admin":false},"assignees":[{"login":"evilj0e","id":914429,"avatar_url":"https://avatars.githubusercontent.com/u/914429?v=3","gravatar_id":"","url":"https://api.github.com/users/evilj0e","html_url":"https://github.com/evilj0e","followers_url":"https://api.github.com/users/evilj0e/followers","following_url":"https://api.github.com/users/evilj0e/following{/other_user}","gists_url":"https://api.github.com/users/evilj0e/gists{/gist_id}","starred_url":"https://api.github.com/users/evilj0e/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evilj0e/subscriptions","organizations_url":"https://api.github.com/users/evilj0e/orgs","repos_url":"https://api.github.com/users/evilj0e/repos","events_url":"https://api.github.com/users/evilj0e/events{/privacy}","received_events_url":"https://api.github.com/users/evilj0e/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls/34/commits","review_comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls/34/comments","review_comment_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls/comments{/number}","comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/issues/34/comments","statuses_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/statuses/5816a02ccb47d47e8e7b116d3ba900db55e3da70","head":{"label":"predatorfromekb:master","ref":"master","sha":"5816a02ccb47d47e8e7b116d3ba900db55e3da70","user":{"login":"predatorfromekb","id":11776751,"avatar_url":"https://avatars.githubusercontent.com/u/11776751?v=3","gravatar_id":"","url":"https://api.github.com/users/predatorfromekb","html_url":"https://github.com/predatorfromekb","followers_url":"https://api.github.com/users/predatorfromekb/followers","following_url":"https://api.github.com/users/predatorfromekb/following{/other_user}","gists_url":"https://api.github.com/users/predatorfromekb/gists{/gist_id}","starred_url":"https://api.github.com/users/predatorfromekb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/predatorfromekb/subscriptions","organizations_url":"https://api.github.com/users/predatorfromekb/orgs","repos_url":"https://api.github.com/users/predatorfromekb/repos","events_url":"https://api.github.com/users/predatorfromekb/events{/privacy}","received_events_url":"https://api.github.com/users/predatorfromekb/received_events","type":"User","site_admin":false},"repo":{"id":74566586,"name":"javascript-task-7","full_name":"predatorfromekb/javascript-task-7","owner":{"login":"predatorfromekb","id":11776751,"avatar_url":"https://avatars.githubusercontent.com/u/11776751?v=3","gravatar_id":"","url":"https://api.github.com/users/predatorfromekb","html_url":"https://github.com/predatorfromekb","followers_url":"https://api.github.com/users/predatorfromekb/followers","following_url":"https://api.github.com/users/predatorfromekb/following{/other_user}","gists_url":"https://api.github.com/users/predatorfromekb/gists{/gist_id}","starred_url":"https://api.github.com/users/predatorfromekb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/predatorfromekb/subscriptions","organizations_url":"https://api.github.com/users/predatorfromekb/orgs","repos_url":"https://api.github.com/users/predatorfromekb/repos","events_url":"https://api.github.com/users/predatorfromekb/events{/privacy}","received_events_url":"https://api.github.com/users/predatorfromekb/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/predatorfromekb/javascript-task-7","description":"Задача «Свадьба Билли»","fork":true,"url":"https://api.github.com/repos/predatorfromekb/javascript-task-7","forks_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/forks","keys_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/keys{/key_id}","collaborators_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/teams","hooks_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/hooks","issue_events_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/issues/events{/number}","events_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/events","assignees_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/assignees{/user}","branches_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/branches{/branch}","tags_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/tags","blobs_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/git/refs{/sha}","trees_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/git/trees{/sha}","statuses_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/statuses/{sha}","languages_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/languages","stargazers_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/stargazers","contributors_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/contributors","subscribers_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/subscribers","subscription_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/subscription","commits_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/commits{/sha}","git_commits_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/git/commits{/sha}","comments_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/comments{/number}","issue_comment_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/issues/comments{/number}","contents_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/contents/{+path}","compare_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/compare/{base}...{head}","merges_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/merges","archive_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/downloads","issues_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/issues{/number}","pulls_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/pulls{/number}","milestones_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/milestones{/number}","notifications_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/labels{/name}","releases_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/releases{/id}","deployments_url":"https://api.github.com/repos/predatorfromekb/javascript-task-7/deployments","created_at":"2016-11-23T10:35:50Z","updated_at":"2016-11-23T10:35:52Z","pushed_at":"2016-12-20T18:22:46Z","git_url":"git://github.com/predatorfromekb/javascript-task-7.git","ssh_url":"git@github.com:predatorfromekb/javascript-task-7.git","clone_url":"https://github.com/predatorfromekb/javascript-task-7.git","svn_url":"https://github.com/predatorfromekb/javascript-task-7","homepage":"","size":29,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"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-2016:master","ref":"master","sha":"4a22d2747c173e3a56c93789b501c871e3d20971","user":{"login":"urfu-2016","id":22170529,"avatar_url":"https://avatars.githubusercontent.com/u/22170529?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2016","html_url":"https://github.com/urfu-2016","followers_url":"https://api.github.com/users/urfu-2016/followers","following_url":"https://api.github.com/users/urfu-2016/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2016/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2016/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2016/subscriptions","organizations_url":"https://api.github.com/users/urfu-2016/orgs","repos_url":"https://api.github.com/users/urfu-2016/repos","events_url":"https://api.github.com/users/urfu-2016/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2016/received_events","type":"Organization","site_admin":false},"repo":{"id":74001255,"name":"javascript-task-7","full_name":"urfu-2016/javascript-task-7","owner":{"login":"urfu-2016","id":22170529,"avatar_url":"https://avatars.githubusercontent.com/u/22170529?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2016","html_url":"https://github.com/urfu-2016","followers_url":"https://api.github.com/users/urfu-2016/followers","following_url":"https://api.github.com/users/urfu-2016/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2016/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2016/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2016/subscriptions","organizations_url":"https://api.github.com/users/urfu-2016/orgs","repos_url":"https://api.github.com/users/urfu-2016/repos","events_url":"https://api.github.com/users/urfu-2016/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2016/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/urfu-2016/javascript-task-7","description":"Задача «Свадьба Билли»","fork":false,"url":"https://api.github.com/repos/urfu-2016/javascript-task-7","forks_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/forks","keys_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/keys{/key_id}","collaborators_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/teams","hooks_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/hooks","issue_events_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/issues/events{/number}","events_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/events","assignees_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/assignees{/user}","branches_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/branches{/branch}","tags_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/tags","blobs_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/git/refs{/sha}","trees_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/git/trees{/sha}","statuses_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/statuses/{sha}","languages_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/languages","stargazers_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/stargazers","contributors_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/contributors","subscribers_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/subscribers","subscription_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/subscription","commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/commits{/sha}","git_commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/git/commits{/sha}","comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/comments{/number}","issue_comment_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/issues/comments{/number}","contents_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/contents/{+path}","compare_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/compare/{base}...{head}","merges_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/merges","archive_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/downloads","issues_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/issues{/number}","pulls_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls{/number}","milestones_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/milestones{/number}","notifications_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/labels{/name}","releases_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/releases{/id}","deployments_url":"https://api.github.com/repos/urfu-2016/javascript-task-7/deployments","created_at":"2016-11-17T07:24:15Z","updated_at":"2016-11-17T14:07:08Z","pushed_at":"2016-12-20T18:22:46Z","git_url":"git://github.com/urfu-2016/javascript-task-7.git","ssh_url":"git@github.com:urfu-2016/javascript-task-7.git","clone_url":"https://github.com/urfu-2016/javascript-task-7.git","svn_url":"https://github.com/urfu-2016/javascript-task-7","homepage":"","size":12,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":51,"mirror_url":null,"open_issues_count":10,"forks":51,"open_issues":10,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls/34"},"html":{"href":"https://github.com/urfu-2016/javascript-task-7/pull/34"},"issue":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-7/issues/34"},"comments":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-7/issues/34/comments"},"review_comments":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls/34/comments"},"review_comment":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-7/pulls/34/commits"},"statuses":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-7/statuses/5816a02ccb47d47e8e7b116d3ba900db55e3da70"}}}}
{"actor":{"display_login":"evilj0e"}}