Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default function (data) {
- // your code starts here
- // console.log(data.grades)
- const graduateStudents = [];
- const nonGraduateStudents = [];
- data.students.forEach(student => {
- const studentGrades = data.grades.filter(gr => gr.studentId === student.id || gr.studentName === student.name);
- const studentExams = data.exams.filter(ex => ex.studentId === student.id || ex.studentName === student.name);
- if(studentExams.length < 2){
- nonGraduateStudents.push({
- id: student.id,
- name: student.name,
- reason: 'exams'});
- }else{
- const gradeSum = studentGrades.reduce((sum, gr) => sum + gr.grade, 0);
- const examSum = studentExams.reduce((sum, ex) => sum + ex.grade, 0);
- const grAvg = gradeSum / studentGrades.length;
- const exAvg = examSum / studentExams.length;
- const totalGr = (grAvg * 0.4) + (exAvg * 0.6);
- if(totalGr >= data.passingGrade){
- graduateStudents.push({
- id: student.id,
- name: student.name,
- grade: totalGr
- })
- }else{
- if(studentExams.length < 2 && totalGr < data.passingGrade){
- nonGraduateStudents.push({
- id: student.id,
- name: student.name,
- reason: 'score and exams'
- });
- }else{
- nonGraduateStudents.push({
- id: student.id,
- name: student.name,
- reason: 'score'
- });
- }
- }
- }
- });
- return{
- name: data.course,
- graduates: graduateStudents,
- nonGraduates: nonGraduateStudents
- }
- // your code ends here
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement