Skip to content

Commit

Permalink
chore: added code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraghazra committed Jul 28, 2020
1 parent f741ec0 commit 8854c6d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/fetchTopLanguages.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,20 @@ async function fetchTopLanguages(username) {

let repoNodes = res.data.data.user.repositories.nodes;

// TODO: perf improvement
repoNodes = repoNodes
.filter((node) => {
return node.languages.edges.length > 0;
})
// flatten the list of language nodes
.reduce((acc, curr) => curr.languages.edges.concat(acc), [])
.sort((a, b) => b.size - a.size)
.reduce((acc, prev) => {
// get the size of the language (bytes)
let langSize = prev.size;

// if we already have the language in the accumulator
// & the current language name is same as previous name
// add the size to the language size.
if (acc[prev.node.name] && prev.node.name === acc[prev.node.name].name) {
langSize = prev.size + acc[prev.node.name].size;
}
Expand Down

0 comments on commit 8854c6d

Please sign in to comment.