Lindergarten
//
// This is only a SKELETON file for the 'Kindergarten Garden' exercise.
// It's been provided as a convenience to get you started writing code faster.
//
const DEFAULT_STUDENTS: Student[] = [
'Alice',
'Bob',
'Charlie',
'David',
'Eve',
'Fred',
'Ginny',
'Harriet',
'Ileana',
'Joseph',
'Kincaid',
'Larry',
]
const PLANT_CODES = {
G: 'grass',
V: 'violets',
R: 'radishes',
C: 'clover',
} as const
type Student = string
type Plant = (typeof PLANT_CODES)[keyof typeof PLANT_CODES]
type Plants = Plant[]
type Pots = Plants[]
export class Garden {
diagram: string;
students: string[];
constructor(diagram: string, students = DEFAULT_STUDENTS) {
this.diagram = diagram;
this.students = students.sort();
}
public plants(student: Student): Plants {
const [firstLine, secondLine] = this.diagram.split("\n");
let index = this.students.indexOf(student);
return [PLANT_CODES[firstLine[index2] as keyof typeof PLANT_CODES],
PLANT_CODES[firstLine[index2+1] as keyof typeof PLANT_CODES],
PLANT_CODES[secondLine[index2] as keyof typeof PLANT_CODES],
PLANT_CODES[secondLine[index2+1]as keyof typeof PLANT_CODES],];
}
}