Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

331
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda