Created
August 9, 2020 03:56
-
-
Save cplpearce/a6990c45eb614a33ecf79c99c1630fc1 to your computer and use it in GitHub Desktop.
Kata 12 - Organizing Instructors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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