Skip to content

Instantly share code, notes, and snippets.

@cplpearce
Created August 9, 2020 03:56
Show Gist options
  • Save cplpearce/a6990c45eb614a33ecf79c99c1630fc1 to your computer and use it in GitHub Desktop.
Save cplpearce/a6990c45eb614a33ecf79c99c1630fc1 to your computer and use it in GitHub Desktop.
Kata 12 - Organizing Instructors
// In this exercise, we will be given a list of instructors and we will create a single object to organize them based on their course.
// Input
const organizeInstructors = function(instructors) {
let org = {};
for (const i of instructors) {
org[i.course] ? org[i.course].push(i.name) : org[i.course] = [i.name];
}
return org;
};
console.log(organizeInstructors([
{name: "Samuel", course: "iOS"},
{name: "Victoria", course: "Web"},
{name: "Karim", course: "Web"},
{name: "Donald", course: "Web"}
]));
console.log(organizeInstructors([
{name: "Brendan", course: "Blockchain"},
{name: "David", course: "Web"},
{name: "Martha", course: "iOS"},
{name: "Carlos", course: "Web"}
]));
/*
Expected Output
{
iOS: ["Samuel"],
Web: ["Victoria", "Karim", "Donald"]
}
{
Blockchain: ["Brendan"],
Web: ["David", "Carlos"],
iOS: ["Martha"]
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment