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