Skip to content

Instantly share code, notes, and snippets.

@InPermutation
Forked from jcbozonier/gist:1257652
Created October 2, 2011 18:24
Show Gist options
  • Save InPermutation/1257730 to your computer and use it in GitHub Desktop.
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.
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