Advertisement
bai_onzi

zad3 Formal Practice

May 6th, 2023
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export default function (data) {
  2.   // your code starts here
  3.   // console.log(data.grades)
  4.   const graduateStudents = [];
  5.   const nonGraduateStudents = [];
  6.  
  7.   data.students.forEach(student => {
  8.       const studentGrades = data.grades.filter(gr => gr.studentId === student.id || gr.studentName === student.name);
  9.       const studentExams = data.exams.filter(ex => ex.studentId === student.id || ex.studentName === student.name);
  10.  
  11.       if(studentExams.length < 2){
  12.           nonGraduateStudents.push({
  13.               id: student.id,
  14.               name: student.name,
  15.               reason: 'exams'});
  16.       }else{
  17.           const gradeSum = studentGrades.reduce((sum, gr) => sum + gr.grade, 0);
  18.           const examSum = studentExams.reduce((sum, ex) => sum + ex.grade, 0);
  19.           const grAvg = gradeSum / studentGrades.length;
  20.           const exAvg = examSum / studentExams.length;
  21.           const totalGr = (grAvg * 0.4) + (exAvg * 0.6);
  22.  
  23.           if(totalGr >= data.passingGrade){
  24.               graduateStudents.push({
  25.                   id: student.id,
  26.                   name: student.name,
  27.                   grade: totalGr
  28.               })
  29.           }else{
  30.               if(studentExams.length < 2 && totalGr < data.passingGrade){
  31.                   nonGraduateStudents.push({
  32.                       id: student.id,
  33.                       name: student.name,
  34.                       reason: 'score and exams'
  35.                   });
  36.               }else{
  37.                   nonGraduateStudents.push({
  38.                       id: student.id,
  39.                       name: student.name,
  40.                       reason: 'score'
  41.                   });
  42.               }
  43.           }
  44.       }
  45.   });
  46.   return{
  47.       name: data.course,
  48.       graduates: graduateStudents,
  49.       nonGraduates: nonGraduateStudents
  50.   }
  51.   // your code ends here
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement