Created
June 9, 2022 10:25
-
-
Save m4rrc0/05806de24f9aa5e1fb851beed64427d4 to your computer and use it in GitHub Desktop.
Revisions
-
m4rrc0 created this gist
Jun 9, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ // 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);