Sha256: c6ea7cfb223547117093bc024175cf1fca6b8acc983a0e381bac30266a47d28f

Contents?: true

Size: 582 Bytes

Versions: 218

Compression:

Stored size: 582 Bytes

Contents

package school

import "sort"

type School map[int][]string

func New() *School {
	return &School{}
}

func (s *School) Add(student string, grade int) {
	(*s)[grade] = append((*s)[grade], student)
}

func (s *School) Grade(level int) []string {
	return (*s)[level]
}

func (s *School) Enrollment() []Grade {
	m := *s
	ls := make([]int, len(m))
	i := 0
	for l := range m {
		ls[i] = l
		i++
	}
	sort.Ints(ls)
	e := make([]Grade, len(m))
	for i, l := range ls {
		t := m[l]
		sort.Strings(t)
		e[i] = Grade{l, t}
	}
	return e
}

type Grade struct {
	Level    int
	Students []string
}

Version data entries

218 entries across 218 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.179 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.178 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.177 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.176 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.175 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.174 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.173 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.172 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.171 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.170 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.169 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.167 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.166 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.165 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.164 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.163 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.162 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.161 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.160 tracks/go/exercises/grade-school/example.go