Skip to content

Commit 0f1937f

Browse files
committed
doneW3Exercise
1 parent e333529 commit 0f1937f

2 files changed

Lines changed: 45 additions & 6 deletions

File tree

Week3/prep-exercises/1-hyf-program/1-find-mentors.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import { modules, students, mentors, classes } from "./hyf.js";
22

3+
4+
const whoCanTeach = mentors.filter(function(mentor){
5+
return mentor.canTeach && mentor.canTeach.length !== 0;
6+
}).map(function(mentor){
7+
return mentor.name;
8+
})
9+
10+
11+
// Call the function to display mentors who can teach at least one course
12+
console.log (whoCanTeach);
13+
314
/**
415
* Tjebbe would like help to get a list of possible mentors for a module.
516
* Fill in this function that finds all the mentors that can teach the given module.
@@ -9,9 +20,12 @@ import { modules, students, mentors, classes } from "./hyf.js";
920
*/
1021
const possibleMentorsForModule = (moduleName) => {
1122
// TODO complete this function
23+
let mentorsPossible = mentors.filter((n) => n.canTeach.includes(moduleName));
24+
let randomIndex = Math.round(Math.random() * mentorsPossible.length);
25+
return mentorsPossible[randomIndex].name;
1226
};
1327
// You can uncomment out this line to try your function
14-
// console.log(possibleMentorsForModule('using-apis'));
28+
console.log(possibleMentorsForModule('using-apis'));
1529

1630
/**
1731
* Tjebbe wants to make it even easier for himself.
@@ -20,7 +34,9 @@ const possibleMentorsForModule = (moduleName) => {
2034
* It should return a single name.
2135
*/
2236
const findMentorForModule = (moduleName) => {
37+
38+
2339
// TODO complete this function
2440
};
2541
// You can uncomment out this line to try your function
26-
// console.log(findMentorForModule('javascript'));
42+
console.log(possibleMentorsForModule);

Week3/prep-exercises/1-hyf-program/2-class-list.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
import { modules, students, mentors, classes } from "./hyf.js";
22

3+
const getPeopleOfClass = (className) => {
4+
let activeClass = classes.find((teaching) => teaching.name === className)
5+
if(!activeClass){
6+
return 'no active class'
7+
}
8+
const people = [];
9+
10+
if (activeClass.students){
11+
people.push(...activeClass.students.map(students=>({name: students, role: 'student'})));
12+
}
13+
14+
if(activeClass.currentModule){
15+
const nameOfMentor = mentors
16+
.filter(mentor => mentor.nowTeaching === activeClass.currentModule)
17+
.map(mentor => ({name:mentor.name, role:'mentor'}));
18+
people.push(...nameOfMentor);
19+
}
20+
return people;
321
/**
422
* We would like to have a list of everyone that is currently participating in a class.
523
* This means the students, but also the mentors that are currently teaching the class.
@@ -11,11 +29,11 @@ import { modules, students, mentors, classes } from "./hyf.js";
1129
*
1230
* [{ name: 'John', role: 'student' }, { name: 'Mary', role: 'mentor' }]
1331
*/
14-
const getPeopleOfClass = (className) => {
32+
1533
// TODO complete this function
1634
};
1735
// You can uncomment out this line to try your function
18-
// console.log(getPeopleOfClass('class34'));
36+
console.log(getPeopleOfClass('class34'));
1937

2038
/**
2139
* We would like to have a complete overview of the current active classes.
@@ -30,7 +48,12 @@ const getPeopleOfClass = (className) => {
3048
* }
3149
*/
3250
const getActiveClasses = () => {
33-
// TODO complete this function
51+
52+
return classes.reduce((activeClass,nameOfMentor) => {
53+
const nameOfClasses = getnameOfClasses(nameOfMentor.name);
54+
activeClass[nameOfClasses.name] = nameOfClasses;
55+
return activeClass;
56+
}, {})
3457
};
3558
// You can uncomment out this line to try your function
36-
// console.log(getActiveClasses());
59+
console.log(getActiveClasses());

0 commit comments

Comments
 (0)