← All Exercises

Generic Min Function

basicgo~15min

Background

Go generics enable type-safe reusable functions without reflection or interface{}.

Problem

Create a generic min function that works with any type satisfying the constraints.Ordered interface.

Input

Two values of any ordered type

Output

The smaller value

Sample tests

Sample 1

Input: min(3, 5)
Expected: 3

Your solution

Learning objective

Learn Go generics and type constraints