{"action":"created","comment":{"url":"https://api.github.com/repos/novoda/dashboard-plugins/pulls/comments/172131056","pull_request_review_id":101095206,"id":172131056,"diff_hunk":"@@ -19,97 +19,49 @@ const parseRss = (url) => {\n }\n \n const toViewState = (items) => {\n-    var mentions = new Map([[\"android\", 0], [\"ios\", 0], [\"cross-platform\", 0]])\n-    mentions.set(\"android\", counUniqueTagsIn(items, androidTags))\n-    mentions.set(\"ios\", counUniqueTagsIn(items, iosTags))\n-    mentions.set(\"cross-platform\", counUniqueTagsIn(items, crossPlatformTags))\n-        \n+    var map = tagsWithUsagesFrom(items)\n     return {\n-        mostUsedTags: mostUsedTagsFrom(items),\n-        crossPlatformMentions: mentions.get(\"cross-platform\"),\n-        androidMentions: mentions.get(\"android\"),\n-        iosMentions: mentions.get(\"ios\")\n+        mostUsedTags: mostUsedTagsFrom(map),\n+        crossPlatformMentions: counUniqueTagsIn(map, crossPlatformTags),\n+        androidMentions: counUniqueTagsIn(map, androidTags),\n+        iosMentions: counUniqueTagsIn(map, iosTags)\n     }\n }\n \n-function mostUsedTagsFrom(items){\n-    return sortMapDescendingByValue(tagsWithUsagesFrom(items))\n-        .splice(0,3)\n-        .map(tagUsage => tagUsage[0])\n+function mostUsedTagsFrom(map) {\n+    return Object.keys(map)\n+        .map(key => [key, map[key]]) // transforms map into array\n+        .sort((firstTag, secondTag) => secondTag[1] - firstTag[1]) // sort array by value\n+        .splice(0, 3) // take the first 3 elements\n+        .map(tagUsage => tagUsage[0]) // take only the names\n         .join(\", \")\n }\n \n-function tagsWithUsagesFrom(items){\n+function tagsWithUsagesFrom(items) {\n     var tagsWithUsages = new Map()\n \n     items\n         .filter(item => item.categories != null)\n-        .map(function(item){ return item.categories})\n-        .map(function(categories){\n-            categories.forEach(category => {\n-                if (tagsWithUsages[category] == undefined){\n-                    tagsWithUsages[category] = 0\n-                } \n-                \n-                tagsWithUsages[category] = tagsWithUsages[category]+1                 \n-            });\n-        })\n-\n-    return tagsWithUsages\n-}\n-\n-function sortMapDescendingByValue(obj)\n-{\n-\tvar sortable=[];\n-\tfor(var key in obj)\n-\t\tif(obj.hasOwnProperty(key))\n-\t\t\tsortable.push([key, obj[key]]);\n-\t\n-\tsortable.sort(function(a, b)\n-\t{\n-\t\tvar x=a[1],\n-\t\t\ty=b[1];\n-\t\treturn y<x ? -1 : y>x ? 1 : 0;\n-    });\n-    \n-    return sortable;\n-}\n-\n-function counUniqueTagsIn(items, tags){\n-    var mentionCount = 0\n+        .map(item => item.categories)\n+        .reduce((prev, curr) => prev.concat(curr))","path":"novoda-blog-diversity/lib/data-source.js","position":88,"original_position":88,"commit_id":"86f7c5124a7ef0a22c7ce3564fe5010d968dbc34","original_commit_id":"86f7c5124a7ef0a22c7ce3564fe5010d968dbc34","user":{"login":"ouchadam","id":1848238,"avatar_url":"https://avatars0.githubusercontent.com/u/1848238?v=4","gravatar_id":"","url":"https://api.github.com/users/ouchadam","html_url":"https://github.com/ouchadam","followers_url":"https://api.github.com/users/ouchadam/followers","following_url":"https://api.github.com/users/ouchadam/following{/other_user}","gists_url":"https://api.github.com/users/ouchadam/gists{/gist_id}","starred_url":"https://api.github.com/users/ouchadam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ouchadam/subscriptions","organizations_url":"https://api.github.com/users/ouchadam/orgs","repos_url":"https://api.github.com/users/ouchadam/repos","events_url":"https://api.github.com/users/ouchadam/events{/privacy}","received_events_url":"https://api.github.com/users/ouchadam/received_events","type":"User","site_admin":false},"body":"ahhh it's an array of arrays, this means you're adding the first element twice.\r\n\r\n```\r\nValue to use as the first argument to the first call of the callback. If no initial value is supplied, the first element in the array will be used. Calling reduce() on an empty array without an initial value is an error.\r\n```\r\n\r\nhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce\r\n","created_at":"2018-03-05T09:39:31Z","updated_at":"2018-03-05T09:39:31Z","html_url":"https://github.com/novoda/dashboard-plugins/pull/5#discussion_r172131056","pull_request_url":"https://api.github.com/repos/novoda/dashboard-plugins/pulls/5","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/novoda/dashboard-plugins/pulls/comments/172131056"},"html":{"href":"https://github.com/novoda/dashboard-plugins/pull/5#discussion_r172131056"},"pull_request":{"href":"https://api.github.com/repos/novoda/dashboard-plugins/pulls/5"}},"in_reply_to_id":172128847},"pull_request":{"url":"https://api.github.com/repos/novoda/dashboard-plugins/pulls/5","id":172534431,"html_url":"https://github.com/novoda/dashboard-plugins/pull/5","diff_url":"https://github.com/novoda/dashboard-plugins/pull/5.diff","patch_url":"https://github.com/novoda/dashboard-plugins/pull/5.patch","issue_url":"https://api.github.com/repos/novoda/dashboard-plugins/issues/5","number":5,"state":"open","locked":false,"title":"Novoda blog diversity (refactor)","user":{"login":"lgvalle","id":354372,"avatar_url":"https://avatars0.githubusercontent.com/u/354372?v=4","gravatar_id":"","url":"https://api.github.com/users/lgvalle","html_url":"https://github.com/lgvalle","followers_url":"https://api.github.com/users/lgvalle/followers","following_url":"https://api.github.com/users/lgvalle/following{/other_user}","gists_url":"https://api.github.com/users/lgvalle/gists{/gist_id}","starred_url":"https://api.github.com/users/lgvalle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lgvalle/subscriptions","organizations_url":"https://api.github.com/users/lgvalle/orgs","repos_url":"https://api.github.com/users/lgvalle/repos","events_url":"https://api.github.com/users/lgvalle/events{/privacy}","received_events_url":"https://api.github.com/users/lgvalle/received_events","type":"User","site_admin":false},"body":"This PR keeps the same logic but updating the code so it looks more JS friendly\r\n","created_at":"2018-03-02T15:43:53Z","updated_at":"2018-03-05T09:39:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dae3ab7d778b6d5bd8b41587a3ff6b4963906670","assignee":null,"assignees":[],"requested_reviewers":[{"login":"tobiasheine","id":1046688,"avatar_url":"https://avatars2.githubusercontent.com/u/1046688?v=4","gravatar_id":"","url":"https://api.github.com/users/tobiasheine","html_url":"https://github.com/tobiasheine","followers_url":"https://api.github.com/users/tobiasheine/followers","following_url":"https://api.github.com/users/tobiasheine/following{/other_user}","gists_url":"https://api.github.com/users/tobiasheine/gists{/gist_id}","starred_url":"https://api.github.com/users/tobiasheine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tobiasheine/subscriptions","organizations_url":"https://api.github.com/users/tobiasheine/orgs","repos_url":"https://api.github.com/users/tobiasheine/repos","events_url":"https://api.github.com/users/tobiasheine/events{/privacy}","received_events_url":"https://api.github.com/users/tobiasheine/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/novoda/dashboard-plugins/pulls/5/commits","review_comments_url":"https://api.github.com/repos/novoda/dashboard-plugins/pulls/5/comments","review_comment_url":"https://api.github.com/repos/novoda/dashboard-plugins/pulls/comments{/number}","comments_url":"https://api.github.com/repos/novoda/dashboard-plugins/issues/5/comments","statuses_url":"https://api.github.com/repos/novoda/dashboard-plugins/statuses/86f7c5124a7ef0a22c7ce3564fe5010d968dbc34","head":{"label":"novoda:novoda_blog_diversity_refactor","ref":"novoda_blog_diversity_refactor","sha":"86f7c5124a7ef0a22c7ce3564fe5010d968dbc34","user":{"login":"novoda","id":74874,"avatar_url":"https://avatars2.githubusercontent.com/u/74874?v=4","gravatar_id":"","url":"https://api.github.com/users/novoda","html_url":"https://github.com/novoda","followers_url":"https://api.github.com/users/novoda/followers","following_url":"https://api.github.com/users/novoda/following{/other_user}","gists_url":"https://api.github.com/users/novoda/gists{/gist_id}","starred_url":"https://api.github.com/users/novoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/novoda/subscriptions","organizations_url":"https://api.github.com/users/novoda/orgs","repos_url":"https://api.github.com/users/novoda/repos","events_url":"https://api.github.com/users/novoda/events{/privacy}","received_events_url":"https://api.github.com/users/novoda/received_events","type":"Organization","site_admin":false},"repo":{"id":117126274,"name":"dashboard-plugins","full_name":"novoda/dashboard-plugins","owner":{"login":"novoda","id":74874,"avatar_url":"https://avatars2.githubusercontent.com/u/74874?v=4","gravatar_id":"","url":"https://api.github.com/users/novoda","html_url":"https://github.com/novoda","followers_url":"https://api.github.com/users/novoda/followers","following_url":"https://api.github.com/users/novoda/following{/other_user}","gists_url":"https://api.github.com/users/novoda/gists{/gist_id}","starred_url":"https://api.github.com/users/novoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/novoda/subscriptions","organizations_url":"https://api.github.com/users/novoda/orgs","repos_url":"https://api.github.com/users/novoda/repos","events_url":"https://api.github.com/users/novoda/events{/privacy}","received_events_url":"https://api.github.com/users/novoda/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/novoda/dashboard-plugins","description":"A collection of plugins for the dashboard","fork":false,"url":"https://api.github.com/repos/novoda/dashboard-plugins","forks_url":"https://api.github.com/repos/novoda/dashboard-plugins/forks","keys_url":"https://api.github.com/repos/novoda/dashboard-plugins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/novoda/dashboard-plugins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/novoda/dashboard-plugins/teams","hooks_url":"https://api.github.com/repos/novoda/dashboard-plugins/hooks","issue_events_url":"https://api.github.com/repos/novoda/dashboard-plugins/issues/events{/number}","events_url":"https://api.github.com/repos/novoda/dashboard-plugins/events","assignees_url":"https://api.github.com/repos/novoda/dashboard-plugins/assignees{/user}","branches_url":"https://api.github.com/repos/novoda/dashboard-plugins/branches{/branch}","tags_url":"https://api.github.com/repos/novoda/dashboard-plugins/tags","blobs_url":"https://api.github.com/repos/novoda/dashboard-plugins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/novoda/dashboard-plugins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/novoda/dashboard-plugins/git/refs{/sha}","trees_url":"https://api.github.com/repos/novoda/dashboard-plugins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/novoda/dashboard-plugins/statuses/{sha}","languages_url":"https://api.github.com/repos/novoda/dashboard-plugins/languages","stargazers_url":"https://api.github.com/repos/novoda/dashboard-plugins/stargazers","contributors_url":"https://api.github.com/repos/novoda/dashboard-plugins/contributors","subscribers_url":"https://api.github.com/repos/novoda/dashboard-plugins/subscribers","subscription_url":"https://api.github.com/repos/novoda/dashboard-plugins/subscription","commits_url":"https://api.github.com/repos/novoda/dashboard-plugins/commits{/sha}","git_commits_url":"https://api.github.com/repos/novoda/dashboard-plugins/git/commits{/sha}","comments_url":"https://api.github.com/repos/novoda/dashboard-plugins/comments{/number}","issue_comment_url":"https://api.github.com/repos/novoda/dashboard-plugins/issues/comments{/number}","contents_url":"https://api.github.com/repos/novoda/dashboard-plugins/contents/{+path}","compare_url":"https://api.github.com/repos/novoda/dashboard-plugins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/novoda/dashboard-plugins/merges","archive_url":"https://api.github.com/repos/novoda/dashboard-plugins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/novoda/dashboard-plugins/downloads","issues_url":"https://api.github.com/repos/novoda/dashboard-plugins/issues{/number}","pulls_url":"https://api.github.com/repos/novoda/dashboard-plugins/pulls{/number}","milestones_url":"https://api.github.com/repos/novoda/dashboard-plugins/milestones{/number}","notifications_url":"https://api.github.com/repos/novoda/dashboard-plugins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/novoda/dashboard-plugins/labels{/name}","releases_url":"https://api.github.com/repos/novoda/dashboard-plugins/releases{/id}","deployments_url":"https://api.github.com/repos/novoda/dashboard-plugins/deployments","created_at":"2018-01-11T16:46:42Z","updated_at":"2018-02-13T21:44:18Z","pushed_at":"2018-03-02T15:43:53Z","git_url":"git://github.com/novoda/dashboard-plugins.git","ssh_url":"git@github.com:novoda/dashboard-plugins.git","clone_url":"https://github.com/novoda/dashboard-plugins.git","svn_url":"https://github.com/novoda/dashboard-plugins","homepage":null,"size":411,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":4,"license":null,"forks":1,"open_issues":4,"watchers":1,"default_branch":"master"}},"base":{"label":"novoda:novoda_blog_diversity","ref":"novoda_blog_diversity","sha":"d996f2414c83b0fbd2ebc9afa9c1275db6e0e8d9","user":{"login":"novoda","id":74874,"avatar_url":"https://avatars2.githubusercontent.com/u/74874?v=4","gravatar_id":"","url":"https://api.github.com/users/novoda","html_url":"https://github.com/novoda","followers_url":"https://api.github.com/users/novoda/followers","following_url":"https://api.github.com/users/novoda/following{/other_user}","gists_url":"https://api.github.com/users/novoda/gists{/gist_id}","starred_url":"https://api.github.com/users/novoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/novoda/subscriptions","organizations_url":"https://api.github.com/users/novoda/orgs","repos_url":"https://api.github.com/users/novoda/repos","events_url":"https://api.github.com/users/novoda/events{/privacy}","received_events_url":"https://api.github.com/users/novoda/received_events","type":"Organization","site_admin":false},"repo":{"id":117126274,"name":"dashboard-plugins","full_name":"novoda/dashboard-plugins","owner":{"login":"novoda","id":74874,"avatar_url":"https://avatars2.githubusercontent.com/u/74874?v=4","gravatar_id":"","url":"https://api.github.com/users/novoda","html_url":"https://github.com/novoda","followers_url":"https://api.github.com/users/novoda/followers","following_url":"https://api.github.com/users/novoda/following{/other_user}","gists_url":"https://api.github.com/users/novoda/gists{/gist_id}","starred_url":"https://api.github.com/users/novoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/novoda/subscriptions","organizations_url":"https://api.github.com/users/novoda/orgs","repos_url":"https://api.github.com/users/novoda/repos","events_url":"https://api.github.com/users/novoda/events{/privacy}","received_events_url":"https://api.github.com/users/novoda/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/novoda/dashboard-plugins","description":"A collection of plugins for the dashboard","fork":false,"url":"https://api.github.com/repos/novoda/dashboard-plugins","forks_url":"https://api.github.com/repos/novoda/dashboard-plugins/forks","keys_url":"https://api.github.com/repos/novoda/dashboard-plugins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/novoda/dashboard-plugins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/novoda/dashboard-plugins/teams","hooks_url":"https://api.github.com/repos/novoda/dashboard-plugins/hooks","issue_events_url":"https://api.github.com/repos/novoda/dashboard-plugins/issues/events{/number}","events_url":"https://api.github.com/repos/novoda/dashboard-plugins/events","assignees_url":"https://api.github.com/repos/novoda/dashboard-plugins/assignees{/user}","branches_url":"https://api.github.com/repos/novoda/dashboard-plugins/branches{/branch}","tags_url":"https://api.github.com/repos/novoda/dashboard-plugins/tags","blobs_url":"https://api.github.com/repos/novoda/dashboard-plugins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/novoda/dashboard-plugins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/novoda/dashboard-plugins/git/refs{/sha}","trees_url":"https://api.github.com/repos/novoda/dashboard-plugins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/novoda/dashboard-plugins/statuses/{sha}","languages_url":"https://api.github.com/repos/novoda/dashboard-plugins/languages","stargazers_url":"https://api.github.com/repos/novoda/dashboard-plugins/stargazers","contributors_url":"https://api.github.com/repos/novoda/dashboard-plugins/contributors","subscribers_url":"https://api.github.com/repos/novoda/dashboard-plugins/subscribers","subscription_url":"https://api.github.com/repos/novoda/dashboard-plugins/subscription","commits_url":"https://api.github.com/repos/novoda/dashboard-plugins/commits{/sha}","git_commits_url":"https://api.github.com/repos/novoda/dashboard-plugins/git/commits{/sha}","comments_url":"https://api.github.com/repos/novoda/dashboard-plugins/comments{/number}","issue_comment_url":"https://api.github.com/repos/novoda/dashboard-plugins/issues/comments{/number}","contents_url":"https://api.github.com/repos/novoda/dashboard-plugins/contents/{+path}","compare_url":"https://api.github.com/repos/novoda/dashboard-plugins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/novoda/dashboard-plugins/merges","archive_url":"https://api.github.com/repos/novoda/dashboard-plugins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/novoda/dashboard-plugins/downloads","issues_url":"https://api.github.com/repos/novoda/dashboard-plugins/issues{/number}","pulls_url":"https://api.github.com/repos/novoda/dashboard-plugins/pulls{/number}","milestones_url":"https://api.github.com/repos/novoda/dashboard-plugins/milestones{/number}","notifications_url":"https://api.github.com/repos/novoda/dashboard-plugins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/novoda/dashboard-plugins/labels{/name}","releases_url":"https://api.github.com/repos/novoda/dashboard-plugins/releases{/id}","deployments_url":"https://api.github.com/repos/novoda/dashboard-plugins/deployments","created_at":"2018-01-11T16:46:42Z","updated_at":"2018-02-13T21:44:18Z","pushed_at":"2018-03-02T15:43:53Z","git_url":"git://github.com/novoda/dashboard-plugins.git","ssh_url":"git@github.com:novoda/dashboard-plugins.git","clone_url":"https://github.com/novoda/dashboard-plugins.git","svn_url":"https://github.com/novoda/dashboard-plugins","homepage":null,"size":411,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":4,"license":null,"forks":1,"open_issues":4,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/novoda/dashboard-plugins/pulls/5"},"html":{"href":"https://github.com/novoda/dashboard-plugins/pull/5"},"issue":{"href":"https://api.github.com/repos/novoda/dashboard-plugins/issues/5"},"comments":{"href":"https://api.github.com/repos/novoda/dashboard-plugins/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/novoda/dashboard-plugins/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/novoda/dashboard-plugins/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/novoda/dashboard-plugins/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/novoda/dashboard-plugins/statuses/86f7c5124a7ef0a22c7ce3564fe5010d968dbc34"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"ouchadam"}}