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

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

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 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