Skip to content

Instantly share code, notes, and snippets.

@higby
Created September 17, 2023 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save higby/5f679ad86b4a36163edf0eb4205724c1 to your computer and use it in GitHub Desktop.
Save higby/5f679ad86b4a36163edf0eb4205724c1 to your computer and use it in GitHub Desktop.
function star(input) {
if (typeof input !== 'number') throw new Error(`Requires number`)
let stars = ''
let floor = Math.floor(input)
for (let i = 0; i < floor; i++) stars += '★'
if (input - floor == 0.5) stars += '½'
return stars
}
star(4.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment