Kodewick
Start learning →
Basic←→0 / 3

Lowest and highest

#002BasicFunctionsSlices4 min

A week of temperatures is in the slice (at least one day). Write MinMax(temps) to return the lowest and the highest, both at once.

Examples
MinMax([]int{18, 25, 21})→(18, 25)
MinMax([]int{7})→(7, 7)
The functionfunc MinMax(temps []int) (int, int)
main.go
package main

func MinMax(temps []int) (int, int) {
	low, high := temps[0], temps[0]
	for _, t := range temps {
		// your code here: lower than low? replace low. Higher than high? replace high
	}
	return low, high
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.