Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

323
Views
How to use filter(), map() to work with values fo an array? JavaScript

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 arrayenter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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:

  • map
  • filter
  • reduce
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!