Sha256: 9cfe712247444920da8680d64eb6d11e9f2c39e34b07dc9cd6ab1ae16764ccca

Contents?: true

Size: 880 Bytes

Versions: 211

Compression:

Stored size: 880 Bytes

Contents

const defaultChildren = [
  'Alice',
  'Bob',
  'Charlie',
  'David',
  'Eve',
  'Fred',
  'Ginny',
  'Harriet',
  'Ileana',
  'Joseph',
  'Kincaid',
  'Larry'
];

const plants = {
  G: 'grass',
  V: 'violets',
  R: 'radishes',
  C: 'clover'
};

function getPlants(pots, index) {
  let plants = [];
  const position = 2*index;
  plants.push(pots[0][position]);
  plants.push(pots[0][position+1]);
  plants.push(pots[1][position]);
  plants.push(pots[1][position+1]);
  return plants;
}

function parse(diagram) {
  return diagram.split('\n').map((row) => [...row].map((sign) => plants[sign]));
}

class Garden {
  constructor(diagram, students) {
    this.students = students || defaultChildren;
    this.students.sort();

    this.students.forEach((student, index) => {
      this[student.toLowerCase()] = getPlants(parse(diagram), index);
    });
  }
}

export default Garden;

Version data entries

211 entries across 211 versions & 1 rubygems

Version Path
trackler-2.2.0.0 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.55 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.54 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.53 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.52 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.51 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.50 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.49 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.48 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.47 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.46 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.45 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.44 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.43 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.42 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.41 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.40 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.39 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.38 tracks/ecmascript/exercises/kindergarten-garden/example.js
trackler-2.1.0.37 tracks/ecmascript/exercises/kindergarten-garden/example.js