1
1
import { modules , students , mentors , classes } from "./hyf.js" ;
2
- //this is a try
3
2
/**
4
3
* Tjebbe would like help to get a list of possible mentors for a module.
5
4
* 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";
8
7
* ['John', 'Mary']
9
8
*/
10
9
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 ;
12
14
} ;
13
- // You can uncomment out this line to try your function
14
- // console.log(possibleMentorsForModule('using-apis'));
15
+
16
+ console . log ( possibleMentorsForModule ( 'using-apis' ) ) ;
15
17
16
18
/**
17
19
* Tjebbe wants to make it even easier for himself.
@@ -21,6 +23,8 @@ const possibleMentorsForModule = (moduleName) => {
21
23
*/
22
24
const findMentorForModule = ( moduleName ) => {
23
25
// TODO complete this function
26
+ const possibleMentors = possibleMentorsForModule ( moduleName ) ;
27
+ return possibleMentors [ Math . floor ( Math . random ( ) * possibleMentors . length ) ] ;
24
28
} ;
25
29
// You can uncomment out this line to try your function
26
- // console.log(findMentorForModule('javascript'));
30
+ console . log ( findMentorForModule ( 'javascript' ) ) ;
0 commit comments