The logic is this:

pick(desiredSize) {
  bestSize = null;
  smallestDelta = INT_MAX;
  desiredArea = desiredSize.width * desiredSize.height;
  previewSizes.forEach(size) {
    area = size.width * size.height;
    delta = abs(area - desiredArea);
    if (delta < smallestDelta) {
      smallestDelta = delta;
      bestSize = size;
    }
  }
  return bestSize;
}

This of course assumes that MxN is a valid preview size but NxM is not--which seems to be the case.