Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebd725e

Browse files
committed
find-mentors completed
1 parent 19b2ace commit ebd725e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { modules, students, mentors, classes } from "./hyf.js";
2-
//this is a try
32
/**
43
* Tjebbe would like help to get a list of possible mentors for a module.
54
* Fill in this function that finds all the mentors that can teach the given module.
@@ -8,10 +7,13 @@ import { modules, students, mentors, classes } from "./hyf.js";
87
* ['John', 'Mary']
98
*/
109
const possibleMentorsForModule = (moduleName) => {
11-
// TODO complete this function
10+
const possibleMentors = mentors
11+
.filter(mentor => mentor.canTeach.indexOf(moduleName) !== -1)
12+
.map(mentor =>mentor.name)
13+
return possibleMentors;
1214
};
13-
// You can uncomment out this line to try your function
14-
// console.log(possibleMentorsForModule('using-apis'));
15+
16+
console.log(possibleMentorsForModule('using-apis'));
1517

1618
/**
1719
* Tjebbe wants to make it even easier for himself.
@@ -21,6 +23,8 @@ const possibleMentorsForModule = (moduleName) => {
2123
*/
2224
const findMentorForModule = (moduleName) => {
2325
// TODO complete this function
26+
const possibleMentors = possibleMentorsForModule(moduleName);
27+
return possibleMentors[Math.floor(Math.random() * possibleMentors.length)];
2428
};
2529
// You can uncomment out this line to try your function
26-
// console.log(findMentorForModule('javascript'));
30+
console.log(findMentorForModule('javascript'));

0 commit comments

Comments
 (0)