-
-
Save lopis/fd7c50dbf6690dd0bb6fac76a1bab5f2 to your computer and use it in GitHub Desktop.
Script for generating TOPs from the list of votes
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
const INNOVATION = 0 | |
const FUN = 1 | |
const THEME = 2 | |
const GAMEPLAY = 3 | |
const GRAPHICS = 4 | |
const TECHNICAL = 5 | |
function getTopFive (category) { | |
return all.map(g => ({ | |
title: g.data.title, score: g.data.result[category], total: g.data.result.reduce((rest, value) => (rest + value), 0) | |
})) | |
.sort((a,b) => a.score < b.score ? 1 : a.score > b.score ? -1 : a.total < b.total ? 1 : a.total > b.total ? -1 : 0) | |
.slice(0, 5) | |
.map(g => [g.title, g.score]) | |
} | |
console.log('Top 5 innovation', getTopFive(INNOVATION)) | |
console.log('Top 5 fun', getTopFive(FUN)) | |
console.log('Top 5 theme', getTopFive(THEME)) | |
console.log('Top 5 gameplay', getTopFive(GAMEPLAY)) | |
console.log('Top 5 graphics', getTopFive(GRAPHICS)) | |
console.log('Top 5 technical', getTopFive(TECHNICAL)) | |
function sortVoters () { | |
const voters = {} | |
all.map(g => { | |
g.data.comments.map(c => { | |
if (!voters[c.login]) { | |
voters[c.login] = 0 | |
} | |
voters[c.login]++ | |
}) | |
}) | |
return Object.entries(voters).sort( (a,b) => a[1] < b[1] ? 1 : a[1] > b[1] ? -1 : 0) | |
} | |
sortVoters() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment