Skip to content

Instantly share code, notes, and snippets.

@andre487
Created March 24, 2020 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andre487/27dc9820e77cdc85adaff09a1800c8fe to your computer and use it in GitHub Desktop.
Save andre487/27dc9820e77cdc85adaff09a1800c8fe to your computer and use it in GitHub Desktop.
Velocity Voting
const weights = {
fcp: 2,
fmp: 5,
js: 3,
tti: 1
}
const negativeWeights = {
fcp: 3,
fmp: 6,
js: 4,
tti: 0
}
function isRequestGood(rumGrades) {
let goodVotes = 0
let badVotes = 0
for (const [metricName, metricGrade] of Object.entries(rumGrades)) {
const weight = weights[metricName]
const negativeWeight = negativeWeights[metricName]
switch (metricGrade) {
case 'instant':
goodVotes += weight * 2
break;
case 'fast':
goodVotes += weight * 1.5
break;
case 'tolerantly':
goodVotes += weight
break;
case 'slow':
badVotes += negativeWeight;
break;
case 'terrible':
badVotes += negativeWeight * 3;
break;
}
}
return goodVotes > badVotes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment