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.139 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.138 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.137 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.136 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.135 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.134 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.133 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.132 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.131 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.130 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.129 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.128 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.127 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.126 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.125 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.124 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.123 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.122 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.121 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.120 tracks/go/exercises/grade-school/example.go