Sha256: 852c65a5d3b24b23fa69986ba2cb1cf14748b9d8ee567901dc94a66714bcc660

Contents?: true

Size: 666 Bytes

Versions: 68

Compression:

Stored size: 666 Bytes

Contents

module.exports = function School() {
  var db = {};

  function add(student, gradeLevel) {
    if (db[gradeLevel]) {
      db[gradeLevel].push(student);
    } else {
      db[gradeLevel] = [student];
    }
  }

  function grade(level) {
    return db[level] ? clone(db[level]).sort() : [];
  }

  function roster() {
    return sortedGrades().reduce(function (sorted, gradeLevel) {
      sorted[gradeLevel] = clone(db[gradeLevel]).sort();
      return sorted;
    }, {});
  }

  function sortedGrades() {
    return Object.keys(db).sort();
  }

  return {
    roster: roster,
    add: add,
    grade: grade
  };
};

function clone(array) {
  return array.slice();
}

Version data entries

68 entries across 68 versions & 1 rubygems

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