Created
April 30, 2021 10:40
-
-
Save jonsage/2884794ed7a694f89bc31696f822e5ce to your computer and use it in GitHub Desktop.
Reduces a ratio to it's smallest form - good for finding smallest placeholder size for image dimensions
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
function ratio(w, h, a = w, b = h) { | |
return b ? ratio(w, h, b, a % b) : [w / a, h / a]; | |
} | |
ratio(640, 480); // [4,3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment