Skip to content

Instantly share code, notes, and snippets.

@jonsage
Created April 30, 2021 10:40
Show Gist options
  • Save jonsage/2884794ed7a694f89bc31696f822e5ce to your computer and use it in GitHub Desktop.
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
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