Skip to content

Instantly share code, notes, and snippets.

@Gioni06
Created April 20, 2022 15:09
Show Gist options
  • Save Gioni06/5a1e873d092a876574ca59bd46adee52 to your computer and use it in GitHub Desktop.
Save Gioni06/5a1e873d092a876574ca59bd46adee52 to your computer and use it in GitHub Desktop.
Calculate the aspect ratio given a width and a height
// 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