/javascript/grade-school/grade-school.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var School = function() {
    this._roster = {};
};

School.prototype = {
  roster: function() {
    return this._roster;
  },

  add: function(name, grade) {
    if (typeof this._roster[grade] === 'undefined') {
      this._roster[grade] = Array();
    }
    this._roster[grade].push(name);
    this._roster[grade].sort();
  },

  grade: function(grade) {
    if (typeof this._roster[grade] !== 'undefined') {
      return this._roster[grade];
    }

    return Array();
  }
};

module.exports = School;

Comments


You're not logged in right now. Please login via GitHub to comment