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

149
Vistas
Connecting data from an array to an object to transform its value with a middleman

What would be the best way to use queued_Dr to alter its values like upcoming_appointments.PCD 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 = 
[["Dr-S","New York","Dr.Salazar"],
 ["Dr-C","Austin","Dr.Connors"],
 ["Dr-J","Austin","Dr.Johnson"],
 ["Dr-S","New York","Dr.Salazar"],
 ["Dr-P","San Juan","Dr.Pearson"],
 ["Dr-J","Austin","Dr.Johnson"]]

Input:

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

Desired Output:

queued_Dr = ["Dr-S","Dr-C","Dr-J","Dr-P"]

Actual Output:

[ undefined, undefined, undefined, undefined ]

Attempt

const mapTo = (arrayWithNames) => {
  var newArray = []; 
  return arrayWithNames.map(name => {
    const appointment = Object.values(all_appointments)
      .find(appointment => appointment[2] === name);
      newArray.push(appointment[0]);
  })
  return newArray;
}
const result = mapTo(queued_Dr)
console.log(result);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The first solution is to find the name in all_appointments and return the corresponding abbreviation.

The second solution is to just compose the abbreviation without other arrays.

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

const all_appointments = [["Dr-S","New York","Dr.Salazar"],["Dr-C","Austin","Dr.Connors"],["Dr-J","Austin","Dr.Johnson"],["Dr-S","New York","Dr.Salazar"],["Dr-P","San Juan","Dr.Pearson"],["Dr-J","Austin","Dr.Johnson"]];
 
const result1 = queued_Dr
  .map((queu) => all_appointments
    .find((appointment) => appointment.at(-1) === queu)
    .at(0));
    
console.log(result1);


const result2 = queued_Dr
  .map((queu) => {
    const [abbr, name] =  queu.split('.');
    return `${abbr}-${name.at(0)}`;
  });
  
console.log(result2);
.as-console-wrapper {max-height: 100% !important; top: 0}

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