exercism/xgo — pull request #38 by soniakeys (2014-05-31 04:23:20+00:00)
Title: grade-school exercise ported from ruby

My first attempt at porting an exercise. I looked at the Ruby code, but renamed some things and of course used types more appropriate to Go. Go has no ordered hash data type. The only ordered collection is a slice, so that's what I returned for the sorted enrollment list. Also for the Grade method, the Ruby test program seemed to be testing for sorted results, but the readme doesn't say that Grade needs to return sorted results so I omitted this test. The API required by the test program is

package school
type School
func New() *School
func (*School) Add(string, int)
func (*School) Grade(int) []string
func (*School) Enrollment() []Grade
type Grade struct {
Level int
Students []string
}

Of interest is that School can be implemented as any type, New just has to create one. The example solution uses a map, so it's not optimal that API works with *School. (Normally you can work with maps directly as values and don't need to work with pointers to them.) But some people may implement School with slices or structs in which case the pointer is needed. A solution implementing School with []Grade would be interesting, for example.

Also, the example here does not address the bonus points described in the readme.