Skip to content

Instantly share code, notes, and snippets.

@IrhaAli
Created October 12, 2022 16:08
Show Gist options
  • Save IrhaAli/b0dc7efd45751cd812b7e9f6d3abfc5c to your computer and use it in GitHub Desktop.
Save IrhaAli/b0dc7efd45751cd812b7e9f6d3abfc5c to your computer and use it in GitHub Desktop.
Given a list of instructors and courses they are teaching, returns the list of instructors teaching a given course.
const organizeInstructors = function(instructors) {
let orgIns = new Object();
for (let i in instructors){
if (orgIns.hasOwnProperty(instructors[i].course)){
orgIns[instructors[i].course].push(instructors[i].name);
}else {
orgIns[instructors[i].course] = [instructors[i].name];
}
}
return orgIns;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment