Skip to content

Commit

Permalink
Utils updated....
Browse files Browse the repository at this point in the history
  • Loading branch information
oitashg committed Sep 21, 2024
1 parent 1175e5a commit 116a08a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/utils/avgRating.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function GetAvgRating(ratingArr) {
if (ratingArr?.length === 0) return 0
const totalReviewCount = ratingArr?.reduce((acc, curr) => {
acc += curr.rating
return acc
}, 0)

const multiplier = Math.pow(10, 1)
const avgReviewCount =
Math.round((totalReviewCount / ratingArr?.length) * multiplier) / multiplier

return avgReviewCount
}

0 comments on commit 116a08a

Please sign in to comment.