Skip to content

Instantly share code, notes, and snippets.

@qWici
Created May 2, 2019 14:05
Show Gist options
  • Save qWici/b221d26f9e1133c6804d96b77b50f59c to your computer and use it in GitHub Desktop.
Save qWici/b221d26f9e1133c6804d96b77b50f59c to your computer and use it in GitHub Desktop.
wilsonScore
// https://www.evanmiller.org/how-not-to-sort-by-average-rating.html
const wilsonScore = (up, down) => {
if (!up) return 0
const n = up + down
const z = 1.64485 // 1.0 = 85%, 1.6 = 95%
const phat = up / n
return (phat + ((z * z) / (2 * n)) - (z * Math.sqrt(((phat * (1 - phat)) + (z * z / (4 * n))) / n))) / (1 + (z * z / n))
}
export default wilsonScore;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment