← Back to challenges

Assign Person to Occupation

JavaScriptHarddata_structures

Instructions

You have two arrays. One shows the names of the people names, while the other shows their occupation jobs. Your task is to create an object displaying each person to their respective occupation.

NamesJobs
AnnieTeacher
StevenEngineer
LisaDoctor
OsmanCashier

Example

const names = ["Dennis", "Vera", "Mabel", "Annette", "Sussan"]
const jobs = ["Butcher", "Programmer", "Doctor", "Teacher", "Lecturer"]

assignPersonToJob(names, jobs) ➞ {
  Dennis: "Butcher",
  Vera: "Programmer",
  Mabel: "Doctor",
  Annette: "Teacher",
  Sussan: "Lecturer"
}

Notes

  • The two arrays have the same length.
  • The index of a name in the names array is the same as the index of the person's job in the jobs array, as shown in the table above.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Find NaN in an Array