File tree Expand file tree Collapse file tree 1 file changed +13
-13
lines changed
lesson_10/libraries/src/loaders Expand file tree Collapse file tree 1 file changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -7,26 +7,26 @@ export class KhaylaSaundersLoader implements Loader {
7
7
getLoaderName ( ) : string {
8
8
return 'khaylasaunders' ;
9
9
}
10
-
10
+ //TA Help/Chatgpt to complete Extra Credit
11
11
async loadData ( ) : Promise < MediaItem [ ] > {
12
- const credits = await this . loadCredits ( ) ;
13
12
const mediaItems = await this . loadMediaItems ( ) ;
14
-
15
- console . log (
16
- `Loaded ${ credits . length } credits and ${ mediaItems . length } media items` ,
17
- ) ;
18
- //Extra credit was generated with the assistance of chatGPT
19
- const creditsMap : Record < string , Credit [ ] > = { } ;
13
+ const credits = await this . loadCredits ( ) ;
20
14
21
15
for ( const credit of credits ) {
22
- const mediaItemId = credit . getMediaItemId ( ) ;
23
- if ( ! creditsMap [ mediaItemId ] ) {
24
- creditsMap [ mediaItemId ] = [ ] ;
16
+ const mediaItem = mediaItems . find (
17
+ ( item ) => item . getId ( ) === credit . getMediaItemId ( ) ,
18
+ ) ;
19
+
20
+ if ( mediaItem ) {
21
+ mediaItem . addCredit ( credit ) ;
25
22
}
26
- creditsMap [ mediaItemId ] . push ( credit ) ;
27
23
}
28
24
29
- return [ ...mediaItems . values ( ) ] ;
25
+ console . log (
26
+ `Loaded ${ credits . length } credits and ${ mediaItems . length } media items` ,
27
+ ) ;
28
+
29
+ return mediaItems ;
30
30
}
31
31
32
32
async loadMediaItems ( ) : Promise < MediaItem [ ] > {
You can’t perform that action at this time.
0 commit comments