Finished
33// convenience to get you started writing code faster.
44//
55
6export class GradeSchool {
6class GradeSchool {
7 constructor() {
8 this._roster = {};
9 }
10
711 /**
812 * @return {string[]}
913 */
1014 roster() {
11 throw new Error('Remove this line and implement the function');
15 const result = [];
16
17 // Edge Case: Empty roster
18 if (Object.keys(this._roster).length === 0) {
19 return result;
20 }
21
22 // Get all grades and sort them numerically
23 const grades = Object.keys(this._roster)
24 .map(grade => parseInt(grade))
25 .sort((a, b) => a - b);
26
27 // For each grade, get sorted students and add to result
28 for (const grade of grades) {
29 const sortedStudents = [...this._roster[grade]].sort();
30 result.push(...sortedStudents);
31 }
32
33 return result;
1234 }
1335
1436 /**
1739 * @return {boolean}
1840 */
1941 add(student, level) {
20 throw new Error('Remove this line and implement the function');
42 // Edge Case: Invalid grade (non-integer or negative)
43 if (!Number.isInteger(level) || level < 0) {
44 return false;
45 }
46
47 // Edge Case: Empty student name
48 if (!student || typeof student !== 'string') {
49 return false;
50 }
51
52 // Check if student already exists in any grade
53 for (const grade in this._roster) {
54 if (this._roster[grade].includes(student)) {
55 // Edge Case: Student already exists in the roster
56 return false;
57 }
58 }
59
60 // Initialize grade array if it doesn't exist
61 if (!this._roster[level]) {
62 this._roster[level] = [];
63 }
64
65 this._roster[level].push(student);
66 return true;
2167 }
2268
2369 /**
2571 * @return {string[]}
2672 */
2773 grade(level) {
28 throw new Error('Remove this line and implement the function');
74 // Edge Case: Grade doesn't exist
75 if (!this._roster[level]) {
76 return [];
77 }
78
79 // Return sorted list of students in the grade
80 return [...this._roster[level]].sort();
2981 }
3082}
83
84// Handled Edge Cases: Empty roster, invalid grade (non-integer or negative), empty student name, student already exists in the roster, grade doesn't exist
85
86export { GradeSchool };
Test NameStatus
Roster is empty when no student is added
Pass
Add a student
Pass
Student is added to the roster
Pass
Adding multiple students in the same grade in the roster
Pass
Multiple students in the same grade are added to the roster
Pass
Cannot add student to same grade in the roster more than once
Pass
Student not added to same grade in the roster more than once
Pass
Adding students in multiple grades
Pass
Students in multiple grades are added to the roster
Pass
Cannot add same student to multiple grades in the roster
Pass
Student not added to multiple grades in the roster
Pass
Students are sorted by grades in the roster
Pass
Students are sorted by name in the roster
Pass
Students are sorted by grades and then by name in the roster
Pass
Grade is empty if no students in the roster
Pass
Grade is empty if no students in that grade
Pass
Student not added to same grade more than once
Pass
Student not added to multiple grades
Pass
Student not added to other grade for multiple grades
Pass
Students are sorted by name in a grade
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.