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.139 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.138 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.137 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.136 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.135 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.134 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.133 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.132 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.131 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.130 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.129 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.128 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.127 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.126 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.125 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.124 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.123 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.122 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.121 tracks/javascript/exercises/kindergarten-garden/example.js
trackler-2.2.1.120 tracks/javascript/exercises/kindergarten-garden/example.js