Last active
February 20, 2016 15:39
-
-
Save mkweick/21e871501ed46980137f to your computer and use it in GitHub Desktop.
Grade School
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class School | |
| def initialize | |
| @school = Hash.new { |school, grade| school[grade] = [] } | |
| end | |
| def to_h | |
| @school.sort.map { |grade, students| [grade, students.sort] }.to_h | |
| end | |
| def add(student, grade) | |
| @school[grade] << student | |
| end | |
| def grade(grade) | |
| @school[grade] | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment