Finished
2525 C: 'clover',
2626};
2727
28export class Garden {
28class Garden {
2929 constructor(diagram, students = DEFAULT_STUDENTS) {
30 throw new Error('Remove this line and implement the function');
30 // Edge Case: Empty diagram
31 if (!diagram) {
32 this.rows = ['', ''];
33 } else {
34 this.rows = diagram.split('\n');
35 // Edge Case: Diagram with only one row
36 if (this.rows.length === 1) {
37 this.rows.push('');
38 }
39 }
40
41 // Edge Case: Empty students array
42 if (!students || students.length === 0) {
43 this.students = [...DEFAULT_STUDENTS];
44 } else {
45 this.students = [...students].sort();
46 }
3147 }
3248
3349 plants(student) {
34 throw new Error('Remove this line and implement the function');
50 // Edge Case: Student not in the list
51 if (!this.students.includes(student)) {
52 return [];
53 }
54
55 const studentIndex = this.students.indexOf(student);
56 const startPosition = studentIndex * 2;
57
58 const plantCodes = [];
59
60 // Get plants from first row
61 if (this.rows[0].length > startPosition) {
62 plantCodes.push(this.rows[0][startPosition]);
63 }
64 if (this.rows[0].length > startPosition + 1) {
65 plantCodes.push(this.rows[0][startPosition + 1]);
66 }
67
68 // Get plants from second row
69 if (this.rows.length > 1 && this.rows[1].length > startPosition) {
70 plantCodes.push(this.rows[1][startPosition]);
71 }
72 if (this.rows.length > 1 && this.rows[1].length > startPosition + 1) {
73 plantCodes.push(this.rows[1][startPosition + 1]);
74 }
75
76 // Edge Case: Invalid plant codes
77 return plantCodes.map(code => {
78 if (PLANT_CODES[code]) {
79 return PLANT_CODES[code];
80 } else {
81 // Handle invalid codes by returning undefined or a default value
82 return 'unknown';
83 }
84 }).filter(plant => plant !== 'unknown');
3585 }
3686}
87
88module.exports = { Garden };
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.