Kodewick
Start learning →
Basic←→0 / 70

Swim badges

#053BasicStructsSlices4 min

Swim 50 metres and you get a badge. In the starter, Swimmer already has a method Passed() that tells you whether someone made it. Write Badges(kids) to return the names that get a badge, in order; nobody gives an empty slice.

Examples
Badges([]Swimmer{{"Ivy", 50}, {"Leo", 25}, {"Max", 100}})→['Ivy', 'Max']
Badges([]Swimmer{})→[]
The functionfunc Badges(kids []Swimmer) []string
main.go
package main

type Swimmer struct {
	Name   string
	Meters int
}

func (s Swimmer) Passed() bool {
	return s.Meters >= 50
}

func Badges(kids []Swimmer) []string {
	names := []string{}
	for _, k := range kids {
		// your code here: if k passed, add the name to names
	}
	return names
}
Ctrl + Enter runs too
Result

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