Sha256: 98458dc353aa4873554e3d1ae8c985b61d58ea995f50fd8e88c9e3752ac2e32b

Contents?: true

Size: 972 Bytes

Versions: 68

Compression:

Stored size: 972 Bytes

Contents

'use strict';

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

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

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

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

function Garden(diagram, students) {
  var instance = {};
  var kids = students || defaultChildren;
  kids.sort();

  kids.forEach(function (student, index) {
    instance[student.toLowerCase()] = getPlants(parse(diagram), index);
  });

  return instance;
}

module.exports = Garden;

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.179 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.178 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.177 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.176 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.175 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.174 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.173 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.172 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.171 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.170 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.169 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.167 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.166 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.165 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.164 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.163 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.162 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.161 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.160 tracks/javascript/exercises/kindergarten-garden/example.js