My task is:
Implement the function duplicateStudents(), which gets the variable "students" and filters for students with the same matriculation number. Firstly, project all elements in students by matriculation number. After that you can filter for duplicates relatively easily. At the end project using the following format: { matrikelnummer: (matrikelnummer), students: [ (students[i], students[j], ... ) ] }.
Implement the invalidGrades() function, which gets the variable "grades" and filters for possibly incorrect notes. For example, in order to keep a manual check as low as possible, the function should determine for which matriculation numbers several grades were transmitted for the same course. Example: For matriculation number X, a 2. 7 and a 2. 3 were transmitted for course Y. However, the function would also take into account the valid case, i. e. for matriculation number X, once a 5,0 and once a 2,3 were transmitted for course Y.
In this task you should only use map(), reduce(), and filter(). Do not implement for-loops.
function duplicateStudents(students) {
return students
// TODO: implement me
}
function invalidGrades(grades) {
return grades
.map((s) => {
// TODO: implement me
return {
matrikelnummer: -1/* put something here */,
grades: []/* put something here */,
};
})
.filter((e) => e.grades.length > 0)
}
The variables students and grades I have in a separate file. I know it might be helpful to upload the files too, but one is 1000 lines long, the other 500. That’s why I’m not uploading them. But I hope it is possible to do the task without the values. It is important to say that the values are represented as an array
I'll give you an example of using reduce on duplicateStudents, that's not returning the expected format but you could go from there.
const duplicateStudents = (students) => {
const grouping = students.reduce((previous, current) => {
if (previous[current.matrikelnummer]) previous[current.matrikelnummer].push(current); // add student if matrikelnummer already exist
else previous[current.matrikelnummer] = [current];
return previous;
}, {});
console.log(grouping);
return //you could process `grouping` to the expected format in here
};
here's preferences for you: