Created
April 20, 2022 15:09
-
-
Save Gioni06/5a1e873d092a876574ca59bd46adee52 to your computer and use it in GitHub Desktop.
Calculate the aspect ratio given a width and a height
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 the aspect ration given a width and a height | |
function aspectRatio(width, height) { | |
// calculate the greates common denominator of two numbers | |
function gcd(a, b) { | |
if (b === 0) { | |
return a; | |
} | |
return gcd(b, a % b); | |
} | |
var gcdValue = gcd(width, height); | |
return width / gcdValue + ':' + height / gcdValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment