Finished
1{
12//
23// This is only a SKELETON file for the 'Kindergarten Garden' exercise.
34// It's been provided as a convenience to get you started writing code faster.
2526 C: 'clover',
2627};
2728
28export class Garden {
29class Garden {
2930 /**
3031 * @param {string} diagram
3132 * @param {string[]} students
3233 */
3334 constructor(diagram, students = DEFAULT_STUDENTS) {
34 throw new Error('Remove this line and implement the function');
35 // Edge Case: Handle empty diagram
36 if (!diagram) {
37 this.rows = ['', ''];
38 } else {
39 this.rows = diagram.split('\n');
40 // Edge Case: Ensure we always have two rows
41 if (this.rows.length === 1) {
42 this.rows.push('');
43 } else if (this.rows.length === 0) {
44 this.rows = ['', ''];
45 }
46 }
47
48 // Edge Case: Handle empty or null students array
49 if (!students || students.length === 0) {
50 this.students = [...DEFAULT_STUDENTS];
51 } else {
52 this.students = [...students].sort();
53 }
3554 }
3655
3756 /**
3958 * @returns {string[]}
4059 */
4160 plants(student) {
42 throw new Error('Remove this line and implement the function');
61 // Edge Case: Student not found in the list
62 const studentIndex = this.students.indexOf(student);
63 if (studentIndex === -1) {
64 return [];
65 }
66
67 const startPosition = studentIndex * 2;
68 const row1 = this.rows[0] || '';
69 const row2 = this.rows[1] || '';
70
71 // Edge Case: Handle when rows are too short for the student's position
72 if (startPosition >= row1.length || startPosition >= row2.length) {
73 return [];
74 }
75
76 const plantCodes = [
77 row1[startPosition],
78 row1[startPosition + 1],
79 row2[startPosition],
80 row2[startPosition + 1]
81 ];
82
83 // Edge Case: Handle invalid plant codes
84 return plantCodes.map(code => {
85 return PLANT_CODES[code] || 'grass'; // Default to grass for unknown codes
86 });
4387 }
4488}
89
90module.exports = { Garden };
91}
Test NameStatus
garden with single student
Pass
different garden with single student
Pass
garden with two students
Pass
second student's garden
Pass
third student's garden
Pass
for Alice, first student's garden
Pass
for Bob, second student's garden
Pass
for Charlie
Pass
for David
Pass
for Eve
Pass
for Fred
Pass
for Ginny
Pass
for Harriet
Pass
for Ileana
Pass
for Joseph
Pass
for Kincaid, second to last student's garden
Pass
for Larry, last student's garden
Pass
for Patricia
Pass
for Roger
Pass
for Samantha
Pass
for Xander
Pass
Bob and Charlie for each garden
Pass

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