Scale an image to fit some maximum dimension using vanilla JavaScript code Fill in the ? with a Javascript expression to set the scale ratio for
  an image having a given height and width so that it fit inside a
  maxdim-by-maxdim square area (touching at least two edges).

function scaleImage(width, height, maxdim) {
  var scale = ?;
  return [scale * width, scale * height];
}



Here is my solution:

function scaleImage(width, height, maxdim) {
  var scale = (width &gt; height ? maxdim/width : maxdim/height);
  return [scale * width, scale * height];
}


Is there a cleaner way of doing this?
I would probably use Math.max(), as that seems more readable to me and would make what is happening more clear. However, I don't think it will affect efficiency in any meaningful way since it's still making a comparison to determine the max.

var scale = maxdim / Math.max(width, height);