Skip to content

Commit

Permalink
rank consistantly and fairly (same rank for same modules)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed Jan 20, 2011
1 parent b52499b commit 83f05e0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions top.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ npm.load({ outfd : null }, function () {

var sorted = Object.keys(authors)
.sort(function (a,b) {
return authors[b] - authors[a]
return authors[b] - authors[a] || (a.toLowerCase() < b.toLowerCase() ? -1 : 1)
})
;

Expand All @@ -29,14 +29,23 @@ npm.load({ outfd : null }, function () {
limit = 1;
}

var fairRank = 1;
var lastVal = -1;
sorted
.slice(start, start + limit)
.forEach(function (name, rank) {
var percent = (authors[name] / total) * 100;

if(authors[name] == lastVal)
rank = fairRank;

console.log(sprintf(
'# %2d %.2f %% %4d %s',
rank + start + 1, percent, authors[name], name
rank + start + 1 , percent, authors[name], name
));

lastVal = authors[name];
fairRank = rank;
})
;
});
Expand Down

0 comments on commit 83f05e0

Please sign in to comment.