Skip to content

Instantly share code, notes, and snippets.

@Hupotronic
Created September 25, 2012 20:21
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 Hupotronic/3784206 to your computer and use it in GitHub Desktop.
Save Hupotronic/3784206 to your computer and use it in GitHub Desktop.
Star-tastic, Gotta Go Fast edition.
// Convert a floating point 0-5 average to a "star" array (0 = none, 1 = half, 2 = full)
var stars = function(x) {
var i=0,k=0,a=[],r=~~(x*2+.5);
while(k<5)a[k++]=r<++i?0:r>i++?2:1;
return a;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment