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.159 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.158 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.157 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.156 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.155 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.154 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.153 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.152 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.151 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.150 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.149 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.148 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.147 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.146 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.145 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.144 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.143 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.142 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.141 tracks/javascript/exercises/grade-school/example.js
trackler-2.2.1.140 tracks/javascript/exercises/grade-school/example.js