Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0.1 #26

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,12 @@ average([134055, 57472, 143135, 365957, 1448459]) // => 4.4

### .score(Number positive, Number negative)

Return a value from 0 to 1.
This method returns a normalized value between 0 and 1, but it's applicable for systems
with only positive and negative ratings (like/dislike, thumbs up/thumbs down).
Examples include videos on YouTube or answers on Stack Overflow.
In these systems, users can express their opinion by voting for either a positive or negative option.

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.

For example, here we calculate score of a blog post with 80 likes and 20
dislikes:
Let's illustrate how this method works with a blog post that received 80 likes and 20 dislikes:

```ts
import { score } from "@ndaidong/average-rating";
Expand All @@ -123,19 +121,17 @@ score(80, 20); // => 0.71

### .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.
This method returns a normalized value between 0 and 1, commonly used in rating systems with 5 levels.
Examples include applications on Google Play Store or books on Amazon.
In these systems, each item receives a user rating between 1 and 5 stars.

For example, here we calculate rating value of a product with:
Let's take a product with a large volume of reviews as an example. Here's how we calculate its rating:

- 134,055 rates of 1 star
- 57,472 rates of 2 stars
- 143,135 rates of 3 stars
- 365,957 rates of 4 stars
- 1,448,459 rates of 5 stars
- 134,055 customers rated it 1 star
- 57,472 gave it a 2-star rating
- There are 143,135 ratings of 3 stars
- It received a 4-star rating from 365,957 users
- And a whopping 1,448,459 customers rated it 5 stars

```ts
import { rate } from "@ndaidong/average-rating";
Expand All @@ -161,6 +157,12 @@ Return a value from 0 to 5.

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

```ts
import { average } from "@ndaidong/average-rating";

average([134055, 57472, 143135, 365957, 1448459]); // => 4.4
```

## Development

Since v3.x.x, we switched to [Deno](https://docs.deno.com/runtime/manual/)
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ndaidong/average-rating",
"version": "3.0.0",
"version": "3.0.1",
"description": "Calculate average score and rating based on Wilson Score Equation",
"homepage": "https://github.com/ndaidong/average-rating",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const rate = (rating: number[] = []): number => {
* Calculate average value for the systems of 5 rating levels
*
* @param rating An array of rating value
* @returns a float value from 0 to 1
* @returns a float value from 0 to 5
*/
export const average = (rating: number[] = []): number => {
const total: number = rating.reduce((prev, current) => {
Expand Down
Loading