how about:

```js
var scaleFactor = widthRatio < heightRatio ? widthRatio : heightRatio;
```