Kodewick
Start learning →
Mini challenge←→0 / 70

Class summary

#063Mini challengeMapsFunctions6 min

scores has the whole class's scores (at least one student, no two the same). Write TopAndPassed(scores) to return the top student's name and how many passed (60 or more) at once. A map's order can change every time, so don't rely on it.

Examples
TopAndPassed(map[string]int{"Ann": 72, "Bob": 95, "Cat": 58})→('Bob', 2)
TopAndPassed(map[string]int{"Dan": 40})→('Dan', 0)
The functionfunc TopAndPassed(scores map[string]int) (string, int)
main.go
package main

func TopAndPassed(scores map[string]int) (string, int) {
	best, passed := "", 0
	for name, s := range scores {
		// your code here: higher? replace best; a pass adds 1 to passed
	}
	return best, passed
}
Ctrl + Enter runs too
Result

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