Wrapper for the Wilson Score Equation to calculate rank based on positive and negative impressions.
Based on How Not To Sort By Average Rating (Lower bound of Wilson score confidence interval for a Bernoulli parameter)
If you are doing any kind of voting or ranking based off a thumbs up or thumbs down logic, the best and most effective way to display the list of items in a relevant order is with this equation.
Client Side:
<script src='wilson.js'></script>
Node.js:
npm install wilson.js
var wilson = require('wilson');
For client side, the wilson object is now bound to the parent scope. Most of the time this will be window.wilson
var scored,
obj = {
name : 'Product 1',
positive : 1337,
negative : 123
};
scored = wilson.score(obj);
/*
Output:
{
name : 'Product 1',
positive : 1337,
negative : 123,
score: 0.9003915795238371 // this is the score
}
*/
Get the Wilson Score of an object or an array. Returns that object or array with score added.
Sort an array based on it's Wilson Score. If objects in array don't already have the score, it will be calculated and added.