Ensure objects are within viewport

I have 4 objects in a scene and I want to adjust the cameras z position such as to ensure that all 4 objects are “seen” by the camera. This is important because I’m building a web player app in a resizable window so I really need to dynamically ensure that they are all seen. I don’t really want to Lerp the z of the camera (checking if they’re within the viewport each frame) because I really want to “snap” it back to the correct z position right way.

Does anyone have any pointers on how to do this using Math or where I might get started?

How about you check if object is visible by any camera?