commit 67062e2429a8393940d93c2ad6f90131c4cf8a57 parent e3fdd13fdbafc6c40d1a3374a9e8888c02fd2d25 Author: Samir Parikh <noreply@samirparikh.com> Date: Thu, 27 Jan 2022 21:22:55 +0000 get all tests to pass Diffstat:
M | grade-school/GradeSchool.pm | | | 7 | ++++--- |
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/grade-school/GradeSchool.pm b/grade-school/GradeSchool.pm @@ -11,9 +11,10 @@ sub roster { foreach my $student (@{ $students }) { push @{ $student_by_grade{$student->[1]} } => $student->[0]; } - foreach my $grade (sort keys %student_by_grade) { - push @roster => sort @{ $student_by_grade{$grade} }; - print "grade $grade: @{ $student_by_grade{$grade} }\n"; + foreach my $student_grade (sort keys %student_by_grade) { + if (not defined $grade or $student_grade == $grade) { + push @roster => sort @{ $student_by_grade{$student_grade} }; + } } return \@roster; }