Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including average-rating with all npm packages installed. Try it out:

var averageRating = require("average-rating")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

average-rating v1.1.12

Calculate average score and rating based on Wilson Score Equation

average-rating

Calculate average and scoring based on Wilson Score Equation

NPM Build Status Coverage Status Dependency Status Known Vulnerabilities

Google app on Google Play

Usage

var av = require('average-rating');
var rate = av.rate;
var average = av.average;
var score = av.score;

// from 1 to 5 stars
let rating = [134055, 57472, 143135, 365957, 1448459];
rate(rating); // --> 0.84
average(rating); // --> 4.4

// get Winson score for a pair of (Positive, Negative) voting
score(0, 1000); // --> 0
score(1000, 0); // --> 0.96
score(1000, 1000); // --> 0.48

API reference

.score(Number positive, Number negative)

Return a value from 0 to 1.

Used for the systems of Positive/Negative rating, such as the videos on YouTube, the answers on StackOverflow, etc. In which, each of item can be voted as good or bad, like or dislike or something like that.

.rate(Array ratings)

Return a value from 0 to 1.

Used for the systems of 5 rating levels, such as the applications on Google Play store, the books on Amazon, etc. In which, each of item can be voted as one of value in the range of 1 to 5 stars.

.average(Array ratings)

Return a value from 0 to 5.

Calculate normal average value for the systems of 5 rating levels.

Test

git clone https://github.com/ndaidong/average-rating.git
cd average-rating
npm install
npm test

License

The MIT License (MIT)

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free