{"action":"created","comment":{"url":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/comments/85790565","pull_request_review_id":6485194,"id":85790565,"diff_hunk":"@@ -6,84 +6,143 @@\n  */\n exports.isStar = true;\n \n-/**\n- * Запрос к коллекции\n- * @param {Array} collection\n- * @params {...Function} – Функции для запроса\n- * @returns {Array}\n- */\n exports.query = function (collection) {\n-    return collection;\n+    var newCollection = collection.map(function (item) {\n+        return Object.assign({}, item);\n+    });\n+    var query = [].slice.call(arguments, 1);\n+    query.sort(compareFunctions);\n+\n+    for (var index = 0; index < query.length; index++) {\n+        newCollection = query[index](newCollection);\n+    }\n+\n+    return newCollection;\n };\n \n-/**\n- * Выбор полей\n- * @params {...String}\n- */\n+function compareFunctions(first, second) {\n+    var priority = ['format', 'limit', 'select', 'sortBy', 'or', 'and', 'filterIn'];\n+\n+    return priority.indexOf(first.name) < priority.indexOf(second.name);\n+}\n+\n+function filterItem(item, fields) {\n+    var keys = Object.keys(item);\n+    var newItem = {};\n+    keys.forEach(function (key) {\n+        if (fields.indexOf(key) !== -1) {\n+            newItem[key] = item[key];\n+        }\n+    });\n+\n+    return newItem;\n+}\n+\n exports.select = function () {\n-    return;\n+    var fields = [].slice.call(arguments);\n+\n+    return function select(collection) {\n+        var newCollection = collection.slice();\n+\n+        return newCollection.map(function (item) {\n+\n+            return filterItem(item, fields);\n+        });\n+    };\n };\n \n-/**\n- * Фильтрация поля по массиву значений\n- * @param {String} property – Свойство для фильтрации\n- * @param {Array} values – Доступные значения\n- */\n+function isHasValue(item, property, values) {\n+    for (var index = 0; index < values.length; index++) {\n+        if (item[property] === values[index]) {\n+            return true;\n+        }\n+    }\n+\n+    return false;\n+}\n+\n exports.filterIn = function (property, values) {\n     console.info(property, values);\n \n-    return;\n+    return function filterIn(collection) {\n+        var newCollection = collection.slice();\n+\n+        return newCollection.filter(function (item) {\n+\n+            return isHasValue(item, property, values);\n+        });\n+    };\n };\n \n-/**\n- * Сортировка коллекции по полю\n- * @param {String} property – Свойство для фильтрации\n- * @param {String} order – Порядок сортировки (asc - по возрастанию; desc – по убыванию)\n- */\n exports.sortBy = function (property, order) {\n     console.info(property, order);\n \n-    return;\n+    return function sortBy(collection) {\n+        var newCollection = collection.slice();\n+        var compareElements = function (firstItem, secondItem) {\n+            if (firstItem[property] > secondItem[property]) {\n+                return 1;\n+            }\n+            if (firstItem[property] <= secondItem[property]) {\n+                return -1;\n+            }\n+        };\n+        newCollection.sort(compareElements);\n+        if (order === 'desc') {\n+            newCollection.reverse();\n+        }\n+\n+        return newCollection;\n+    };\n };\n \n-/**\n- * Форматирование поля\n- * @param {String} property – Свойство для фильтрации\n- * @param {Function} formatter – Функция для форматирования\n- */\n exports.format = function (property, formatter) {\n     console.info(property, formatter);\n \n-    return;\n+    return function format(collection) {\n+        var newCollection = collection.slice();\n+        newCollection.forEach(function (item) {","path":"lego.js","position":129,"original_position":129,"commit_id":"832d8aff07f0ec2ede186f8d4313635d0c451115","original_commit_id":"832d8aff07f0ec2ede186f8d4313635d0c451115","user":{"login":"Dotokoto","id":8973726,"avatar_url":"https://avatars.githubusercontent.com/u/8973726?v=3","gravatar_id":"","url":"https://api.github.com/users/Dotokoto","html_url":"https://github.com/Dotokoto","followers_url":"https://api.github.com/users/Dotokoto/followers","following_url":"https://api.github.com/users/Dotokoto/following{/other_user}","gists_url":"https://api.github.com/users/Dotokoto/gists{/gist_id}","starred_url":"https://api.github.com/users/Dotokoto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dotokoto/subscriptions","organizations_url":"https://api.github.com/users/Dotokoto/orgs","repos_url":"https://api.github.com/users/Dotokoto/repos","events_url":"https://api.github.com/users/Dotokoto/events{/privacy}","received_events_url":"https://api.github.com/users/Dotokoto/received_events","type":"User","site_admin":false},"body":"return newCollection.forEach(...)","created_at":"2016-10-31T17:33:30Z","updated_at":"2016-10-31T17:33:30Z","html_url":"https://github.com/urfu-2016/javascript-task-4/pull/7#discussion_r85790565","pull_request_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/comments/85790565"},"html":{"href":"https://github.com/urfu-2016/javascript-task-4/pull/7#discussion_r85790565"},"pull_request":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/7","id":91495979,"html_url":"https://github.com/urfu-2016/javascript-task-4/pull/7","diff_url":"https://github.com/urfu-2016/javascript-task-4/pull/7.diff","patch_url":"https://github.com/urfu-2016/javascript-task-4/pull/7.patch","issue_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/issues/7","number":7,"state":"open","locked":false,"title":"Нартов Никита","user":{"login":"nikitc","id":14799681,"avatar_url":"https://avatars.githubusercontent.com/u/14799681?v=3","gravatar_id":"","url":"https://api.github.com/users/nikitc","html_url":"https://github.com/nikitc","followers_url":"https://api.github.com/users/nikitc/followers","following_url":"https://api.github.com/users/nikitc/following{/other_user}","gists_url":"https://api.github.com/users/nikitc/gists{/gist_id}","starred_url":"https://api.github.com/users/nikitc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikitc/subscriptions","organizations_url":"https://api.github.com/users/nikitc/orgs","repos_url":"https://api.github.com/users/nikitc/repos","events_url":"https://api.github.com/users/nikitc/events{/privacy}","received_events_url":"https://api.github.com/users/nikitc/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-29T17:32:19Z","updated_at":"2016-10-31T17:33:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b45ae021f0d7f0dc09359b771d4026b7aa706194","assignee":{"login":"Dotokoto","id":8973726,"avatar_url":"https://avatars.githubusercontent.com/u/8973726?v=3","gravatar_id":"","url":"https://api.github.com/users/Dotokoto","html_url":"https://github.com/Dotokoto","followers_url":"https://api.github.com/users/Dotokoto/followers","following_url":"https://api.github.com/users/Dotokoto/following{/other_user}","gists_url":"https://api.github.com/users/Dotokoto/gists{/gist_id}","starred_url":"https://api.github.com/users/Dotokoto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dotokoto/subscriptions","organizations_url":"https://api.github.com/users/Dotokoto/orgs","repos_url":"https://api.github.com/users/Dotokoto/repos","events_url":"https://api.github.com/users/Dotokoto/events{/privacy}","received_events_url":"https://api.github.com/users/Dotokoto/received_events","type":"User","site_admin":false},"assignees":[{"login":"Dotokoto","id":8973726,"avatar_url":"https://avatars.githubusercontent.com/u/8973726?v=3","gravatar_id":"","url":"https://api.github.com/users/Dotokoto","html_url":"https://github.com/Dotokoto","followers_url":"https://api.github.com/users/Dotokoto/followers","following_url":"https://api.github.com/users/Dotokoto/following{/other_user}","gists_url":"https://api.github.com/users/Dotokoto/gists{/gist_id}","starred_url":"https://api.github.com/users/Dotokoto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dotokoto/subscriptions","organizations_url":"https://api.github.com/users/Dotokoto/orgs","repos_url":"https://api.github.com/users/Dotokoto/repos","events_url":"https://api.github.com/users/Dotokoto/events{/privacy}","received_events_url":"https://api.github.com/users/Dotokoto/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/7/commits","review_comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/7/comments","review_comment_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/comments{/number}","comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/issues/7/comments","statuses_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/statuses/832d8aff07f0ec2ede186f8d4313635d0c451115","head":{"label":"nikitc:master","ref":"master","sha":"832d8aff07f0ec2ede186f8d4313635d0c451115","user":{"login":"nikitc","id":14799681,"avatar_url":"https://avatars.githubusercontent.com/u/14799681?v=3","gravatar_id":"","url":"https://api.github.com/users/nikitc","html_url":"https://github.com/nikitc","followers_url":"https://api.github.com/users/nikitc/followers","following_url":"https://api.github.com/users/nikitc/following{/other_user}","gists_url":"https://api.github.com/users/nikitc/gists{/gist_id}","starred_url":"https://api.github.com/users/nikitc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikitc/subscriptions","organizations_url":"https://api.github.com/users/nikitc/orgs","repos_url":"https://api.github.com/users/nikitc/repos","events_url":"https://api.github.com/users/nikitc/events{/privacy}","received_events_url":"https://api.github.com/users/nikitc/received_events","type":"User","site_admin":false},"repo":{"id":72277777,"name":"javascript-task-4","full_name":"nikitc/javascript-task-4","owner":{"login":"nikitc","id":14799681,"avatar_url":"https://avatars.githubusercontent.com/u/14799681?v=3","gravatar_id":"","url":"https://api.github.com/users/nikitc","html_url":"https://github.com/nikitc","followers_url":"https://api.github.com/users/nikitc/followers","following_url":"https://api.github.com/users/nikitc/following{/other_user}","gists_url":"https://api.github.com/users/nikitc/gists{/gist_id}","starred_url":"https://api.github.com/users/nikitc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikitc/subscriptions","organizations_url":"https://api.github.com/users/nikitc/orgs","repos_url":"https://api.github.com/users/nikitc/repos","events_url":"https://api.github.com/users/nikitc/events{/privacy}","received_events_url":"https://api.github.com/users/nikitc/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nikitc/javascript-task-4","description":"Задача «Картофельная вечеринка Билли»","fork":true,"url":"https://api.github.com/repos/nikitc/javascript-task-4","forks_url":"https://api.github.com/repos/nikitc/javascript-task-4/forks","keys_url":"https://api.github.com/repos/nikitc/javascript-task-4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nikitc/javascript-task-4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nikitc/javascript-task-4/teams","hooks_url":"https://api.github.com/repos/nikitc/javascript-task-4/hooks","issue_events_url":"https://api.github.com/repos/nikitc/javascript-task-4/issues/events{/number}","events_url":"https://api.github.com/repos/nikitc/javascript-task-4/events","assignees_url":"https://api.github.com/repos/nikitc/javascript-task-4/assignees{/user}","branches_url":"https://api.github.com/repos/nikitc/javascript-task-4/branches{/branch}","tags_url":"https://api.github.com/repos/nikitc/javascript-task-4/tags","blobs_url":"https://api.github.com/repos/nikitc/javascript-task-4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nikitc/javascript-task-4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nikitc/javascript-task-4/git/refs{/sha}","trees_url":"https://api.github.com/repos/nikitc/javascript-task-4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nikitc/javascript-task-4/statuses/{sha}","languages_url":"https://api.github.com/repos/nikitc/javascript-task-4/languages","stargazers_url":"https://api.github.com/repos/nikitc/javascript-task-4/stargazers","contributors_url":"https://api.github.com/repos/nikitc/javascript-task-4/contributors","subscribers_url":"https://api.github.com/repos/nikitc/javascript-task-4/subscribers","subscription_url":"https://api.github.com/repos/nikitc/javascript-task-4/subscription","commits_url":"https://api.github.com/repos/nikitc/javascript-task-4/commits{/sha}","git_commits_url":"https://api.github.com/repos/nikitc/javascript-task-4/git/commits{/sha}","comments_url":"https://api.github.com/repos/nikitc/javascript-task-4/comments{/number}","issue_comment_url":"https://api.github.com/repos/nikitc/javascript-task-4/issues/comments{/number}","contents_url":"https://api.github.com/repos/nikitc/javascript-task-4/contents/{+path}","compare_url":"https://api.github.com/repos/nikitc/javascript-task-4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nikitc/javascript-task-4/merges","archive_url":"https://api.github.com/repos/nikitc/javascript-task-4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nikitc/javascript-task-4/downloads","issues_url":"https://api.github.com/repos/nikitc/javascript-task-4/issues{/number}","pulls_url":"https://api.github.com/repos/nikitc/javascript-task-4/pulls{/number}","milestones_url":"https://api.github.com/repos/nikitc/javascript-task-4/milestones{/number}","notifications_url":"https://api.github.com/repos/nikitc/javascript-task-4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nikitc/javascript-task-4/labels{/name}","releases_url":"https://api.github.com/repos/nikitc/javascript-task-4/releases{/id}","deployments_url":"https://api.github.com/repos/nikitc/javascript-task-4/deployments","created_at":"2016-10-29T10:08:42Z","updated_at":"2016-10-29T10:08:43Z","pushed_at":"2016-10-29T18:27:40Z","git_url":"git://github.com/nikitc/javascript-task-4.git","ssh_url":"git@github.com:nikitc/javascript-task-4.git","clone_url":"https://github.com/nikitc/javascript-task-4.git","svn_url":"https://github.com/nikitc/javascript-task-4","homepage":"","size":11,"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":"7478a115049e4e20247defea7e2f8dc6f49a8239","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":71762351,"name":"javascript-task-4","full_name":"urfu-2016/javascript-task-4","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-4","description":"Задача «Картофельная вечеринка Билли»","fork":false,"url":"https://api.github.com/repos/urfu-2016/javascript-task-4","forks_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/forks","keys_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/teams","hooks_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/hooks","issue_events_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/issues/events{/number}","events_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/events","assignees_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/assignees{/user}","branches_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/branches{/branch}","tags_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/tags","blobs_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/git/refs{/sha}","trees_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/statuses/{sha}","languages_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/languages","stargazers_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/stargazers","contributors_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/contributors","subscribers_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/subscribers","subscription_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/subscription","commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/commits{/sha}","git_commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/git/commits{/sha}","comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/comments{/number}","issue_comment_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/issues/comments{/number}","contents_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/contents/{+path}","compare_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/merges","archive_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/downloads","issues_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/issues{/number}","pulls_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls{/number}","milestones_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/milestones{/number}","notifications_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/labels{/name}","releases_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/releases{/id}","deployments_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/deployments","created_at":"2016-10-24T07:19:05Z","updated_at":"2016-10-27T17:04:42Z","pushed_at":"2016-10-31T17:09:35Z","git_url":"git://github.com/urfu-2016/javascript-task-4.git","ssh_url":"git@github.com:urfu-2016/javascript-task-4.git","clone_url":"https://github.com/urfu-2016/javascript-task-4.git","svn_url":"https://github.com/urfu-2016/javascript-task-4","homepage":"","size":13,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":50,"mirror_url":null,"open_issues_count":20,"forks":50,"open_issues":20,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/7"},"html":{"href":"https://github.com/urfu-2016/javascript-task-4/pull/7"},"issue":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/issues/7"},"comments":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/statuses/832d8aff07f0ec2ede186f8d4313635d0c451115"}}}}
{"actor":{"display_login":"Dotokoto"}}