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

174
Vistas
JavaScript - specific queried from two databases

I need help with a JavaScript task. How do I get something specific queried from two databases?

Task: View the index.js file Implement the gradeOverview() function, which gets the variables students and grades and creates a grade overview for each student. Thereby each element in the students array should be projected to an object in the following format: { student: (students[i]), grades: [(grades[j], grades[j+k], ...)] }

This is my function which accesses both databases and should retrieve and display a value from one database at a time based on the "student number".

    function gradeOverview(students, grades) {
      const result = students.map((student) => [
        {
          student: student,
          grade: grades.reduce((grades, grade) => {
            const student number = grade.studentnumber;
            if (grades[matriculationnumber] == null) grades[matriculationnumber] = [];
            grades[matriculationnumber].push(grade);
            return grades;
          }),
        },
      ]);

  console.log(result);

  return result;

  // TODO: implement me
}

The Data:

var students = [{
        "matrikelnummer": 4636,
        "vorname": "Vérane",
        "nachname": "Voase"
    }]

var grades = [{
            "id": 628,
            "matrikelnummer": 4636,
            "grade": "3,3"

        },
        {
            "id": 886,
            "matrikelnummer": 4636,
            "grade": "5,0"
        }]

Output:

"student": {
            "matrikelnummer": 4636,
            "vorname": "Vérane",
            "nachname": "Voase"
        },
        "grades": [
            {
                "id": 628,
                "matrikelnummer": 4636,
                "grade": "3,3"
            },
            {
                "id": 886,
                "matrikelnummer": 4636
                "grade": "3,6"
            }
        ]
    },
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Updated: Fiddle Link https://jsfiddle.net/uzrodex3/

I hope i guessed correctly your incoming data you put into gradeOverview function.

const studentsQueryResponse = [
    {
        name: "John Doe",
        studentNumber: 123
    },
    {
        name: "Johan Doe",
        studentNumber: 321
    },
    {
        name: "Jane Doe",
        studentNumber: 111
    }
]
const gradesQueryResponse = [
    {
        studentNumber: 123,
        grade: 1
    },
    {
        studentNumber: 123,
        grade: 3
    },
    {
        studentNumber: 321,
        grade: 5
    },
    {
        studentNumber: 123,
        grade: 1
    }
]

There is your function which returns in this case

[
   {
      "student": {
         "name":"John Doe",
         "studentNumber":123
      },
      "grade":[1,3,1]
   },
   {  
      "student": {
         "name":"Johan Doe",
         "studentNumber":321
      },
      "grade":[5]
   },
   {
      "student": {
         "name":"Jane Doe",
         "studentNumber":111
      },
      "grade":[]
   }
]

If you want to return whole grade object in array, then just remove map line which returns grade property value from grade object

function gradeOverview(students, grades) {
    console.log("Input arguments", students, grades)

    const results = students.map((student) => {

        return {
            student: student,
            grade: grades
                .filter((gradeObject) => gradeObject.studentNumber === student.studentNumber)
                .map((gradeObject) => gradeObject.grade)
        }
    });


    console.log("Results", results);
    
    return results;
}

And then you call your function

gradeOverview(studenstQueryResponse, gradesQueryResponse)
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