Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda