{"action":"created","comment":{"url":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/comments/87508582","pull_request_review_id":8120358,"id":87508582,"diff_hunk":"@@ -13,58 +120,163 @@ exports.isStar = true;\n  * @returns {Array}\n  */\n exports.query = function (collection) {\n-    return collection;\n+    var collectionCopy = cloneCollection(collection);\n+    var args = [].slice.call(arguments, 1);\n+    var selectArguments = [];\n+    var nonSelectArgs = [];\n+    args.forEach(function (queryFunction) {\n+        if (queryFunction.queryType === QUERY_TYPES.SELECT) {\n+            var compatibleArguments = getCompatibleSelectArguments(\n+                collection, queryFunction.queryArguments);\n+            if (compatibleArguments.length > 0) {\n+                selectArguments.push(compatibleArguments);\n+            }\n+        } else {\n+            nonSelectArgs.push(queryFunction);\n+        }\n+    });\n+    args = nonSelectArgs;\n+    if (selectArguments.length > 0) {\n+        var selectArgumentsIntersection = getIntersection(selectArguments);\n+        args.push(exports.select.apply(this, selectArgumentsIntersection));\n+    }\n+    args.sort(function (a, b) {\n+        return a.queryType - b.queryType;\n+    });\n+    args.forEach(function (queryFunction) {\n+        collectionCopy = queryFunction.query(collectionCopy);\n+    });\n+\n+    return collectionCopy;\n };\n \n /**\n  * Выбор полей\n  * @params {...String}\n+ * @returns {Object} - query-object\n  */\n exports.select = function () {\n-    return;\n+    var args = [].slice.call(arguments, 0);\n+\n+    return {\n+        queryType: QUERY_TYPES.SELECT,\n+        queryArguments: args,\n+        query: function (collection) {\n+            var selected = [];\n+            collection.forEach(function (item) {\n+                var selectedItem = {};\n+                args.forEach(function (property) {\n+                    if (item.hasOwnProperty(property)) {\n+                        selectedItem[property] = item[property];\n+                    }\n+                });\n+                selected.push(selectedItem);\n+            });\n+\n+            return selected;\n+        }\n+    };\n+\n };\n \n /**\n  * Фильтрация поля по массиву значений\n  * @param {String} property – Свойство для фильтрации\n  * @param {Array} values – Доступные значения\n+ * @returns {Object} - query-object\n  */\n exports.filterIn = function (property, values) {\n     console.info(property, values);\n \n-    return;\n+    return {\n+        queryType: QUERY_TYPES.FILTER,\n+        query: function (collection) {\n+            var filtered = [];\n+            collection.forEach(function (item) {\n+                if (values.length === 0 || !item.hasOwnProperty(property) ||\n+                    values.indexOf(item[property]) !== -1) {\n+                    filtered.push(item);\n+                }\n+            });\n+\n+            return filtered;\n+        }\n+    };\n };\n \n+\n /**\n  * Сортировка коллекции по полю\n  * @param {String} property – Свойство для фильтрации\n  * @param {String} order – Порядок сортировки (asc - по возрастанию; desc – по убыванию)\n+ * @returns {Object} - query-object\n  */\n exports.sortBy = function (property, order) {\n     console.info(property, order);\n+    var SORT_DIRECTION = {\n+        ASCENDING: 'asc',\n+        DESCENDING: 'desc'\n+    };\n \n-    return;\n+    return {\n+        queryType: QUERY_TYPES.SORT,\n+        query: function (collection) {\n+            var newCollection = getCollectionCopy(collection);\n+            var orderMultiplyer = order === SORT_DIRECTION.DESCENDING ? -1 : 1;\n+\n+            return newCollection.sort(function (a, b) {\n+                return orderMultiplyer * (String(a[property])).localeCompare(String(b[property]));","path":"lego.js","position":null,"original_position":232,"commit_id":"5a7064cc8a5f1f54dd7523d95a658bcc7d684ff5","original_commit_id":"3307310a1b29aff45a4d1e2fd27e9302ca2844b6","user":{"login":"Dodo888","id":10964067,"avatar_url":"https://avatars.githubusercontent.com/u/10964067?v=3","gravatar_id":"","url":"https://api.github.com/users/Dodo888","html_url":"https://github.com/Dodo888","followers_url":"https://api.github.com/users/Dodo888/followers","following_url":"https://api.github.com/users/Dodo888/following{/other_user}","gists_url":"https://api.github.com/users/Dodo888/gists{/gist_id}","starred_url":"https://api.github.com/users/Dodo888/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dodo888/subscriptions","organizations_url":"https://api.github.com/users/Dodo888/orgs","repos_url":"https://api.github.com/users/Dodo888/repos","events_url":"https://api.github.com/users/Dodo888/events{/privacy}","received_events_url":"https://api.github.com/users/Dodo888/received_events","type":"User","site_admin":false},"body":"Какой у тебя в этом случае будет порядок для чисел 1, 2, 10, 100? Лексикографический порядок для них - 1,10,100,2. ","created_at":"2016-11-10T23:22:31Z","updated_at":"2016-11-10T23:22:31Z","html_url":"https://github.com/urfu-2016/javascript-task-4/pull/23#discussion_r87508582","pull_request_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/comments/87508582"},"html":{"href":"https://github.com/urfu-2016/javascript-task-4/pull/23#discussion_r87508582"},"pull_request":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/23","id":91748568,"html_url":"https://github.com/urfu-2016/javascript-task-4/pull/23","diff_url":"https://github.com/urfu-2016/javascript-task-4/pull/23.diff","patch_url":"https://github.com/urfu-2016/javascript-task-4/pull/23.patch","issue_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/issues/23","number":23,"state":"open","locked":false,"title":"Фомин Денис","user":{"login":"ilearnf","id":11571410,"avatar_url":"https://avatars.githubusercontent.com/u/11571410?v=3","gravatar_id":"","url":"https://api.github.com/users/ilearnf","html_url":"https://github.com/ilearnf","followers_url":"https://api.github.com/users/ilearnf/followers","following_url":"https://api.github.com/users/ilearnf/following{/other_user}","gists_url":"https://api.github.com/users/ilearnf/gists{/gist_id}","starred_url":"https://api.github.com/users/ilearnf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilearnf/subscriptions","organizations_url":"https://api.github.com/users/ilearnf/orgs","repos_url":"https://api.github.com/users/ilearnf/repos","events_url":"https://api.github.com/users/ilearnf/events{/privacy}","received_events_url":"https://api.github.com/users/ilearnf/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-11-01T08:41:30Z","updated_at":"2016-11-10T23:22:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"94b0511f25e651ef07365249b7a87502c4713246","assignee":{"login":"Dodo888","id":10964067,"avatar_url":"https://avatars.githubusercontent.com/u/10964067?v=3","gravatar_id":"","url":"https://api.github.com/users/Dodo888","html_url":"https://github.com/Dodo888","followers_url":"https://api.github.com/users/Dodo888/followers","following_url":"https://api.github.com/users/Dodo888/following{/other_user}","gists_url":"https://api.github.com/users/Dodo888/gists{/gist_id}","starred_url":"https://api.github.com/users/Dodo888/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dodo888/subscriptions","organizations_url":"https://api.github.com/users/Dodo888/orgs","repos_url":"https://api.github.com/users/Dodo888/repos","events_url":"https://api.github.com/users/Dodo888/events{/privacy}","received_events_url":"https://api.github.com/users/Dodo888/received_events","type":"User","site_admin":false},"assignees":[{"login":"Dodo888","id":10964067,"avatar_url":"https://avatars.githubusercontent.com/u/10964067?v=3","gravatar_id":"","url":"https://api.github.com/users/Dodo888","html_url":"https://github.com/Dodo888","followers_url":"https://api.github.com/users/Dodo888/followers","following_url":"https://api.github.com/users/Dodo888/following{/other_user}","gists_url":"https://api.github.com/users/Dodo888/gists{/gist_id}","starred_url":"https://api.github.com/users/Dodo888/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dodo888/subscriptions","organizations_url":"https://api.github.com/users/Dodo888/orgs","repos_url":"https://api.github.com/users/Dodo888/repos","events_url":"https://api.github.com/users/Dodo888/events{/privacy}","received_events_url":"https://api.github.com/users/Dodo888/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/23/commits","review_comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/23/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/23/comments","statuses_url":"https://api.github.com/repos/urfu-2016/javascript-task-4/statuses/5a7064cc8a5f1f54dd7523d95a658bcc7d684ff5","head":{"label":"ilearnf:master","ref":"master","sha":"5a7064cc8a5f1f54dd7523d95a658bcc7d684ff5","user":{"login":"ilearnf","id":11571410,"avatar_url":"https://avatars.githubusercontent.com/u/11571410?v=3","gravatar_id":"","url":"https://api.github.com/users/ilearnf","html_url":"https://github.com/ilearnf","followers_url":"https://api.github.com/users/ilearnf/followers","following_url":"https://api.github.com/users/ilearnf/following{/other_user}","gists_url":"https://api.github.com/users/ilearnf/gists{/gist_id}","starred_url":"https://api.github.com/users/ilearnf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilearnf/subscriptions","organizations_url":"https://api.github.com/users/ilearnf/orgs","repos_url":"https://api.github.com/users/ilearnf/repos","events_url":"https://api.github.com/users/ilearnf/events{/privacy}","received_events_url":"https://api.github.com/users/ilearnf/received_events","type":"User","site_admin":false},"repo":{"id":72518500,"name":"javascript-task-4","full_name":"ilearnf/javascript-task-4","owner":{"login":"ilearnf","id":11571410,"avatar_url":"https://avatars.githubusercontent.com/u/11571410?v=3","gravatar_id":"","url":"https://api.github.com/users/ilearnf","html_url":"https://github.com/ilearnf","followers_url":"https://api.github.com/users/ilearnf/followers","following_url":"https://api.github.com/users/ilearnf/following{/other_user}","gists_url":"https://api.github.com/users/ilearnf/gists{/gist_id}","starred_url":"https://api.github.com/users/ilearnf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilearnf/subscriptions","organizations_url":"https://api.github.com/users/ilearnf/orgs","repos_url":"https://api.github.com/users/ilearnf/repos","events_url":"https://api.github.com/users/ilearnf/events{/privacy}","received_events_url":"https://api.github.com/users/ilearnf/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ilearnf/javascript-task-4","description":"Задача «Картофельная вечеринка Билли»","fork":true,"url":"https://api.github.com/repos/ilearnf/javascript-task-4","forks_url":"https://api.github.com/repos/ilearnf/javascript-task-4/forks","keys_url":"https://api.github.com/repos/ilearnf/javascript-task-4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ilearnf/javascript-task-4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ilearnf/javascript-task-4/teams","hooks_url":"https://api.github.com/repos/ilearnf/javascript-task-4/hooks","issue_events_url":"https://api.github.com/repos/ilearnf/javascript-task-4/issues/events{/number}","events_url":"https://api.github.com/repos/ilearnf/javascript-task-4/events","assignees_url":"https://api.github.com/repos/ilearnf/javascript-task-4/assignees{/user}","branches_url":"https://api.github.com/repos/ilearnf/javascript-task-4/branches{/branch}","tags_url":"https://api.github.com/repos/ilearnf/javascript-task-4/tags","blobs_url":"https://api.github.com/repos/ilearnf/javascript-task-4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ilearnf/javascript-task-4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ilearnf/javascript-task-4/git/refs{/sha}","trees_url":"https://api.github.com/repos/ilearnf/javascript-task-4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ilearnf/javascript-task-4/statuses/{sha}","languages_url":"https://api.github.com/repos/ilearnf/javascript-task-4/languages","stargazers_url":"https://api.github.com/repos/ilearnf/javascript-task-4/stargazers","contributors_url":"https://api.github.com/repos/ilearnf/javascript-task-4/contributors","subscribers_url":"https://api.github.com/repos/ilearnf/javascript-task-4/subscribers","subscription_url":"https://api.github.com/repos/ilearnf/javascript-task-4/subscription","commits_url":"https://api.github.com/repos/ilearnf/javascript-task-4/commits{/sha}","git_commits_url":"https://api.github.com/repos/ilearnf/javascript-task-4/git/commits{/sha}","comments_url":"https://api.github.com/repos/ilearnf/javascript-task-4/comments{/number}","issue_comment_url":"https://api.github.com/repos/ilearnf/javascript-task-4/issues/comments{/number}","contents_url":"https://api.github.com/repos/ilearnf/javascript-task-4/contents/{+path}","compare_url":"https://api.github.com/repos/ilearnf/javascript-task-4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ilearnf/javascript-task-4/merges","archive_url":"https://api.github.com/repos/ilearnf/javascript-task-4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ilearnf/javascript-task-4/downloads","issues_url":"https://api.github.com/repos/ilearnf/javascript-task-4/issues{/number}","pulls_url":"https://api.github.com/repos/ilearnf/javascript-task-4/pulls{/number}","milestones_url":"https://api.github.com/repos/ilearnf/javascript-task-4/milestones{/number}","notifications_url":"https://api.github.com/repos/ilearnf/javascript-task-4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ilearnf/javascript-task-4/labels{/name}","releases_url":"https://api.github.com/repos/ilearnf/javascript-task-4/releases{/id}","deployments_url":"https://api.github.com/repos/ilearnf/javascript-task-4/deployments","created_at":"2016-11-01T08:39:56Z","updated_at":"2016-11-01T08:39:57Z","pushed_at":"2016-11-10T09:35:30Z","git_url":"git://github.com/ilearnf/javascript-task-4.git","ssh_url":"git@github.com:ilearnf/javascript-task-4.git","clone_url":"https://github.com/ilearnf/javascript-task-4.git","svn_url":"https://github.com/ilearnf/javascript-task-4","homepage":"","size":30,"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-11-10T15:56:05Z","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":83,"mirror_url":null,"open_issues_count":18,"forks":83,"open_issues":18,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/23"},"html":{"href":"https://github.com/urfu-2016/javascript-task-4/pull/23"},"issue":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/issues/23"},"comments":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/pulls/23/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/23/commits"},"statuses":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-4/statuses/5a7064cc8a5f1f54dd7523d95a658bcc7d684ff5"}}}}
{"actor":{"display_login":"Dodo888"}}