Connecting data from an array to an object to transform its value with a middleman
Solution 1:
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}