First time posting on here and was hoping to get some help I can't seem to figure out how to do this problem. It's basically to create a function that receives an array of objects that returns a new object.
For some reason, push won't go through and returns the error property of push is undefined.
const organizeInstructors = function(instructors) {
let output = {}; // so the obvious which is to create the object
for (let i = 0; i < instructors.length; i++) {
if (!output[instructors[course]]) {
output[instructors[course]] = instructors[course];
} else {
output[instructors[course]].push(instructors[name]);
}
}
return output;
};
console.log(organizeInstructors([{
name: "Samuel",
course: "iOS"
},
{
name: "Victoria",
course: "Web"
},
{
name: "Karim",
course: "Web"
},
{
name: "Donald",
course: "Web"
}
]));
expected output
{
iOS: ["Samuel"],
Web: ["Victoria", "Karim", "Donald"]
}
Thanks for any advice or hints you guys can give
instructors[course]andinstructors.course