Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Student(name){
- this.name = name;
- this.assistence = ['X', 'X'];
- this.normalize = function(assistence){
- for(var i = 0; i < assistence.length; i++){
- if(assistence[i] == 1){
- this.assistence[0] = '1';
- }
- if(assistence[i] == 2){
- this.assistence[1] = '2';
- }
- }
- }
- }
- function Group(){
- this.students = {};
- }
- Group.prototype.add = function(name){
- var student = new Student(name);
- this.students[name] = student;
- }
- Group.prototype.asistio = function(name, assistence){
- this.students[name].normalize(assistence);
- }
- Group.prototype.review = function(){
- var str = "";
- for(var key in this.students){
- //console.log(key, this.students[key].assistence);
- str += key + "|" + this.students[key].assistence.join(',')+"\n";
- }
- return str;
- }
- var group = new Group();
- group.add('Silvana');
- group.add('Inti');
- group.add('Steph');
- group.asistio('Silvana', [1, 2]);
- group.asistio('Inti', [1]);
- group.asistio('Steph', [2]);
- //console.log(group);
- console.log(group.review());
- /*
- Silvana | 1, 2
- Inti | 1, -
- Steph | -, 2
- */
Add Comment
Please, Sign In to add comment