Skip to content

Commit 1e87db3

Browse files
committed
prep-ex-week3
1 parent 0dfceaf commit 1e87db3

2 files changed

Lines changed: 35 additions & 14 deletions

File tree

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import { modules, students, mentors, classes } from "./hyf.js";
88
* ['John', 'Mary']
99
*/
1010
const possibleMentorsForModule = (moduleName) => {
11-
// TODO complete this function
11+
const possibleMentors = mentors.filter(mentor => mentor.canTeach.includes(moduleName));
12+
13+
return possibleMentors.map(mentor => mentor.name);
14+
1215
};
13-
// You can uncomment out this line to try your function
14-
// console.log(possibleMentorsForModule('using-apis'));
16+
17+
console.log(possibleMentorsForModule('using-apis'));
1518

1619
/**
1720
* Tjebbe wants to make it even easier for himself.
@@ -20,7 +23,9 @@ const possibleMentorsForModule = (moduleName) => {
2023
* It should return a single name.
2124
*/
2225
const findMentorForModule = (moduleName) => {
23-
// TODO complete this function
26+
const possibleMentors = possibleMentorsForModule(moduleName);
27+
const random = Math.floor(Math.random() * possibleMentors.length);
28+
return possibleMentors[random];
2429
};
25-
// You can uncomment out this line to try your function
26-
// console.log(findMentorForModule('javascript'));
30+
31+
console.log(findMentorForModule('javascript'));

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { modules, students, mentors, classes } from "./hyf.js";
2-
32
/**
43
* We would like to have a list of everyone that is currently participating in a class.
54
* This means the students, but also the mentors that are currently teaching the class.
@@ -12,10 +11,21 @@ import { modules, students, mentors, classes } from "./hyf.js";
1211
* [{ name: 'John', role: 'student' }, { name: 'Mary', role: 'mentor' }]
1312
*/
1413
const getPeopleOfClass = (className) => {
15-
// TODO complete this function
16-
};
17-
// You can uncomment out this line to try your function
18-
// console.log(getPeopleOfClass('class34'));
14+
const classInfo = classes.find(classes => classes.name === className);
15+
if (!classInfo) {
16+
return[];
17+
}
18+
const currentModule = classInfo.currentModule;
19+
const classStudents = students .filter(student => student.class === className)
20+
.map(student => ({ name: student.name, role:'student'}));
21+
22+
const classMentors = mentors.filter( mentor => mentor.nowTeaching === currentModule)
23+
.map(mentor => ({name: mentor.name, role: 'mentor'}));
24+
25+
return [...classStudents, ...classMentors];
26+
};
27+
28+
console.log(getPeopleOfClass('class34'));
1929

2030
/**
2131
* We would like to have a complete overview of the current active classes.
@@ -30,7 +40,13 @@ const getPeopleOfClass = (className) => {
3040
* }
3141
*/
3242
const getActiveClasses = () => {
33-
// TODO complete this function
43+
const activeClasses = classes.filter(classes => classes.active);
44+
const result = {};
45+
activeClasses.forEach(classes => {
46+
result[classes.name] = getPeopleOfClass(classes.name);
47+
});
48+
49+
return result;
3450
};
35-
// You can uncomment out this line to try your function
36-
// console.log(getActiveClasses());
51+
52+
console.log(getActiveClasses());

0 commit comments

Comments
 (0)