Created
September 3, 2015 22:30
-
-
Save gaboelnuevo/f7639c69616a50aa1c3d to your computer and use it in GitHub Desktop.
Calculate a ratio from two numbers
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
//calculate aspect ratio | |
// Via: http://stackoverflow.com/questions/1186414/whats-the-algorithm-to-calculate-aspect-ratio-i-need-an-output-like-43-169 | |
function gcd (a, b) { | |
return (b == 0) ? a : gcd (b, a%b); | |
} | |
var w = screen.width; | |
var h = screen.height; | |
var r = gcd (w, h); | |
console.log("Dimensions = " + w + " x " + h); | |
console.log("Aspect ratio = " + w/r + ":" + h/r); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: This will exceed maximum calls stack size if one of the arguments is NaN.