Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sinky/8351745 to your computer and use it in GitHub Desktop.
Save sinky/8351745 to your computer and use it in GitHub Desktop.
/* GCD */
function gcd (a, b) { return (b == 0) ? a : gcd (b, a%b); } // Source: http://stackoverflow.com/a/1186465
/* ratio is to get the gcd and divide each component by the gcd, then return a string with the typical colon-separated value */
function ratio(x,y) {c=gcd(x,y); return ""+(x/c)+":"+(y/c)}
ratio(1920,1080)
/* "16:9" */
ratio(320,240)
/* "4:3" */
ratio(360,240)
/* "3:2" */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment