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.119 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.118 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.117 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.116 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.115 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.114 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.113 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.111 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.110 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.109 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.108 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.107 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.106 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.105 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.104 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.103 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.102 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.101 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.100 tracks/go/exercises/grade-school/example.go
trackler-2.2.1.99 tracks/go/exercises/grade-school/example.go