index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. const studentsArr = [{
  2. name: 'Сергей',
  3. surname: 'Войлов',
  4. ratingPoint: 1000,
  5. schoolPoint: 1000,
  6. course: 2,
  7. },
  8. {
  9. name: 'Татьяна',
  10. surname: 'Коваленко',
  11. ratingPoint: 880,
  12. schoolPoint: 700,
  13. course: 1,
  14. },
  15. {
  16. name: 'Анна',
  17. surname: 'Кугир',
  18. ratingPoint: 1430,
  19. schoolPoint: 1200,
  20. course: 3,
  21. },
  22. {
  23. name: 'Станислав',
  24. surname: 'Щелоков',
  25. ratingPoint: 1130,
  26. schoolPoint: 1060,
  27. course: 2,
  28. },
  29. {
  30. name: 'Денис',
  31. surname: 'Хрущ',
  32. ratingPoint: 1000,
  33. schoolPoint: 990,
  34. course: 4,
  35. },
  36. {
  37. name: 'Татьяна',
  38. surname: 'Капустник',
  39. ratingPoint: 650,
  40. schoolPoint: 500,
  41. course: 3,
  42. },
  43. {
  44. name: 'Максим',
  45. surname: 'Меженский',
  46. ratingPoint: 990,
  47. schoolPoint: 1100,
  48. course: 1,
  49. },
  50. {
  51. name: 'Денис',
  52. surname: 'Марченко',
  53. ratingPoint: 570,
  54. schoolPoint: 1300,
  55. course: 4,
  56. },
  57. {
  58. name: 'Антон',
  59. surname: 'Завадский',
  60. ratingPoint: 1090,
  61. schoolPoint: 1010,
  62. course: 3
  63. },
  64. {
  65. name: 'Игорь',
  66. surname: 'Куштым',
  67. ratingPoint: 870,
  68. schoolPoint: 790,
  69. course: 1,
  70. },
  71. {
  72. name: 'Инна',
  73. surname: 'Скакунова',
  74. ratingPoint: 1560,
  75. schoolPoint: 200,
  76. course: 2,
  77. },
  78. ];
  79. const budgetLimit = 5;
  80. const allowRating = 800;
  81. let id = 1;
  82. class CreateStudent {
  83. constructor(student) {
  84. CreateStudent.id.call(this)
  85. this.name = student.name;
  86. this.surname = student.surname;
  87. this.ratingPoint = student.ratingPoint;
  88. this.schoolPoint = student.schoolPoint;
  89. this.isSelfPayment = (student.ratingPoint >= allowRating ) ? student.isSelfPayment = false : student.isSelfPayment = true;
  90. this.course = student.course;
  91. }
  92. static id = function() { return this.id = id++;};
  93. getTypeOfStudy() {if(this.isSelfPayment === false) {
  94. return `бюджет`
  95. }
  96. return `контракт`
  97. }
  98. getFullInfo() {return `Я - ${this.name} ${this.surname}, рейтинговый балл - ${this.ratingPoint}, форма обучения - ${this.getTypeOfStudy()}`};
  99. getRankedPlace() {
  100. const index = fullListStudents.findIndex((stud) => stud.id == this.id)
  101. return index + 1;
  102. }
  103. };
  104. let contract = [];
  105. const setAllCreatedStudentsByConstructor = arrOfStudents => {
  106. arrOfStudents = studentsArr.map((student) => new CreateStudent(student));
  107. arrOfStudents.sort(function(currentStudent, nextStudent) {return nextStudent.ratingPoint - currentStudent.ratingPoint || nextStudent.schoolPoint - currentStudent.schoolPoint});
  108. arrOfStudents.map(function(student, index) {
  109. if(index >= budgetLimit) {
  110. student.isSelfPayment = true;
  111. if (student.isSelfPayment === true) {
  112. contract.push(student)
  113. }
  114. }
  115. })
  116. budget = arrOfStudents.filter(student => student.isSelfPayment === false)
  117. fullListStudents = [...budget,...contract].sort(function(currentStudent, nextStudent) {return nextStudent.ratingPoint - currentStudent.ratingPoint || nextStudent.schoolPoint - currentStudent.schoolPoint});
  118. }
  119. setAllCreatedStudentsByConstructor(studentsArr)
  120. console.log(budget)
  121. console.log(contract)
  122. console.log(fullListStudents)
  123. console.log(contract[3].getFullInfo())
  124. console.log(fullListStudents[2].getRankedPlace())
  125. class Intern extends CreateStudent {
  126. constructor(companyName) {
  127. super(companyName);
  128. this.companyName = companyName = 'Google';
  129. }
  130. getFullInternInfo() {return `Я - ${this.name} ${this.surname}, рейтинговый балл - ${this.ratingPoint}, форма обучения - ${this.getTypeOfStudy()}, интерн в компании ${this.companyName}`};
  131. }
  132. interns = fullListStudents.map((companyName) => new Intern(companyName, 'Google'))
  133. console.log(interns[3].getFullInternInfo())