Added minmax function.

All tests passing. #5268