title: JS: Getting aspect ratio using a margin of X pixels
body: <p>I've got an application which displays a webpage in a frame. This frame is supposed to be 1280x720 pixels, but sometimes it renders as 1280x719 or 1281x720. Now i've found this script to calculate a ratio based on any given width and height:</p>
  
  <pre><code>function gcd (a, b) { 
      return (b == 0) ? a : gcd (b, a%b);
  }
  </code></pre>
  
  <p>This works perfectly fine when the viewport is exactly 1280x720 pixels, but when the viewport is 1280x719 or 1281x720, it returns 1280:719 or 1281:720 as the aspect ratio.</p>
  
  <p>What I would like the script to do is to still return 16:9.</p>
  
  <p>I've thought of using an array with some default aspect ratios (16:9, 4:3, ...). This way the array could be checked for every margin difference untill a result is found. I just don't know how I can check for each of these margin values in a fast way. Hopefully anyone in here can help me achieve the above.</p>