Skip to content

Instantly share code, notes, and snippets.

@thecotne
Created February 26, 2019 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecotne/d7630dec23ebb1aad24a5d5d0e355a4c to your computer and use it in GitHub Desktop.
Save thecotne/d7630dec23ebb1aad24a5d5d0e355a4c to your computer and use it in GitHub Desktop.
function fit ([wi, hi], [ws, hs]) {
const ri = wi / hi
const rs = ws / hs
return rs > ri ? [wi * hs / hi, hs] : [ws, hi * ws / wi]
}
// usage
const [width, height] = fit([16, 9], [2560, 1600])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment