Created
June 9, 2022 10:25
-
-
Save m4rrc0/05806de24f9aa5e1fb851beed64427d4 to your computer and use it in GitHub Desktop.
rating function ★★★☆☆
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Credits: https://twitter.com/builderio/status/1534246051892408320 | |
const rating = stars => '★★★★★☆☆☆☆☆'.slice(5 - stars, 10 - stars); | |
// OR | |
const rating = max => star => "★".repeat(Math.min(star, max)).padEnd(max,"☆"); | |
// It caps the value to max then gets an input number of stars | |
// Examples: | |
const rating5 = rating(5); | |
rating5(3); // "★★★☆☆" | |
const rating3 = rating(3); | |
const rating10 = rating(10); | |
const like = rating(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment