Garden

in #ita13 days ago

//

// 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 = [

'Alice',

'Bob',

'Charlie',

'David',

'Eve',

'Fred',

'Ginny',

'Harriet',

'Ileana',

'Joseph',

'Kincaid',

'Larry',

];

const PLANT_CODES = {

G: 'grass',

V: 'violets',

R: 'radishes',

C: 'clover',

};

export class Garden {

constructor(diagram, students = DEFAULT_STUDENTS) {

this.diagram = diagram;

this.students = students.sort();

}

plants(student) {

let [firstLine, secondLine] = this.diagram.split("\n");

let index = this.students.indexOf(student);

return [PLANT\_CODES[firstLine[index\*2]],

           PLANT\_CODES[firstLine[index\*2+1]],

           PLANT\_CODES[secondLine[index\*2]],

           PLANT\_CODES[secondLine[index\*2+1]]];

}

}