Created
July 2, 2020 22:35
-
-
Save andreiskandar/337f91e821f693ab7a55d4e26ec1051d to your computer and use it in GitHub Desktop.
Array of instructor objects that will return a new object in organized way
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
/* | |
Create a function named organizeInstructors that will receive an array of instructor objects, | |
and will return a new object that has the following format: | |
*/ | |
const organizeInstructors = function(instructors) { | |
let organize = {}; | |
instructors.forEach(i => { | |
if(!organize[i.course]){ | |
organize[i.course] = []; | |
organize[i.course].push(i.name); | |
} else { | |
organize[i.course].push(i.name); | |
} | |
}) | |
return organize; | |
} | |
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"} | |
])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment