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

177
Visualizações
Connecting data from an array to an object by using a middleman object

Is there a way to connect queued_Dr to upcoming_appointments by using all_appointments

What would be the best approach to this problem?

var queued_Dr = ["Dr.Salazar",["Dr.Connors","Dr.Johnson"],"Dr.Pearson"]


upcoming_appointments =
[{"DOB":"01-27-2002","name":"Judy, W." ,"PCD":"Dr-S"}
    ,{"DOB":"08-15-1995","name":"John, V." ,"PCD":"Dr-C"}
    ,{"DOB":"07-05-1992","name":"David, C.","PCD":"Dr-S"}
    ,{"DOB":"01-15-2002","name":"Anna, S." ,"PCD":"Dr-J"}
    ,{"DOB":"01-15-2002","name":"Jeff, D." ,"PCD":"Dr-P"}]


all_appointments = 
{"0": ["Dr-S","New York","Dr.Salazar"],
    "1": ["Dr-C","Austin","Dr.Connors"],
    "2": ["Dr-J","Austin","Dr.Johnson"],
    "3": ["Dr-S","New York","Dr.Salazar"],
    "4": ["Dr-P","San Juan","Dr.Pearson"],
    "5": ["Dr-J","Austin","Dr.Johnson"]}

Goal Output

"Dr.Salazar" -> "Dr-S"
["Dr.Connors","Dr.Johnson"] -> "Dr-C" or "Dr-J"
"Dr.Pearson"] -> "Dr-P"

inputs are queued_Dr and upcoming_appointments.PCD

//Tried to see if the values where in the same dictionary 

function find_by_exception_name(dr_name) {
    return all_appointments.find((row) => row.upcoming_appointments == dr_name || row.upcoming_appointments.includes(dr_name));
} 
//would return true or false if a Doctors name from queued_Dr and upcoming appointments existed in all_appointments
          
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

From the information you have given to us you don't need upcoming_appointments at all. The code below will return to you the desired result.

const mapTo = (arrayWithNames) => {
  return arrayWithNames.map(name => {
    if (Array.isArray(name)) {
      return mapTo(name);
    }

    const appointment = Object.values(all_appointments)
      .find(appointment => appointment[2] === name);
    const upcommingAppointment = upcoming_appointments
      .find(currentAppointment => currentAppointment.PCD === appointment[0])

    console.log(`This is the upcomming appointment for your doctor ${JSON.stringify(upcommingAppointment)}`)
    return `${name} -> ${appointment[0]}` 
  })
}
const result = mapTo(queued_Dr)

Also, please format your code properly. In JavaScript it is not a good practice to put opening braces on a new line as this might cause an unexpected result in some scenarios.

Edit: I've added the console.log so you can see the proper appointment for your doctor but you haven't explained how you want to use it.

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