Guest User

Untitled

a guest
Feb 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. function Student(name){
  2. this.name = name;
  3. this.assistence = ['X', 'X'];
  4. this.normalize = function(assistence){
  5. for(var i = 0; i < assistence.length; i++){
  6. if(assistence[i] == 1){
  7. this.assistence[0] = '1';
  8. }
  9. if(assistence[i] == 2){
  10. this.assistence[1] = '2';
  11. }
  12. }
  13. }
  14. }
  15.  
  16. function Group(){
  17. this.students = {};
  18. }
  19.  
  20. Group.prototype.add = function(name){
  21. var student = new Student(name);
  22. this.students[name] = student;
  23. }
  24.  
  25. Group.prototype.asistio = function(name, assistence){
  26. this.students[name].normalize(assistence);
  27. }
  28.  
  29. Group.prototype.review = function(){
  30. var str = "";
  31. for(var key in this.students){
  32. //console.log(key, this.students[key].assistence);
  33. str += key + "|" + this.students[key].assistence.join(',')+"\n";
  34. }
  35. return str;
  36. }
  37.  
  38. var group = new Group();
  39.  
  40. group.add('Silvana');
  41. group.add('Inti');
  42. group.add('Steph');
  43.  
  44. group.asistio('Silvana', [1, 2]);
  45. group.asistio('Inti', [1]);
  46. group.asistio('Steph', [2]);
  47.  
  48. //console.log(group);
  49. console.log(group.review());
  50.  
  51. /*
  52. Silvana | 1, 2
  53. Inti | 1, -
  54. Steph | -, 2
  55. */
Add Comment
Please, Sign In to add comment