-
-
Save InPermutation/1257730 to your computer and use it in GitHub Desktop.
Aggregating the scores by lol and associating with the name of the user who created it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var aggregate_scores_by_lol = function(votes, lols, users){ | |
var vote_count = lols.reduce(function(p,lol,i,r){ return p[lol.id] = 0, p; }, {}); | |
var lol_dictionary = lols.reduce(function(p,lol,i,r){ return p[lol.id] = lol, p}, {}); | |
votes.forEach(function(vote){ vote_count[vote.lol_id]++; }); | |
var vote_count_keys = vote_count.map(function(el,ix){ return ix;}); | |
var sorted_lol_ids = vote_count_keys.sort(function(a, b){ | |
return vote_count[b] - vote_count[a]; | |
}); | |
return sorted_lol_ids.map(function(lol_id){ | |
var lol = lol_dictionary[lol_id]; | |
lol_scores.push({ | |
id: lol_id, | |
score: vote_count[lol_id], | |
url: lol.lol_url, | |
user_id: lol.user_id, | |
user_name: users[lol.user_id].name | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment