File tree Expand file tree Collapse file tree 1 file changed +21
-18
lines changed
Expand file tree Collapse file tree 1 file changed +21
-18
lines changed Original file line number Diff line number Diff line change @@ -12,26 +12,29 @@ export class QuestionGenerator {
1212 async generateQuestion ( ) {
1313 const questionsIdArray = this . generateRandomIdArray ( ) ;
1414 const rightAnswerId = this . randomRightAnswer ( questionsIdArray ) ;
15- const result = {
16- image : '' ,
17- answers : [ ] ,
18- rightAnswer : '' ,
19- } ;
2015
21- await Promise . all (
22- questionsIdArray . map ( ( id ) =>
23- this . fetchData ( this . mode , id ) . then ( ( data ) => {
24- result . answers . push ( data . name ) ;
25- if ( rightAnswerId == id ) {
26- result . image = btoa (
27- `static/assets/img/modes/${ this . mode } /${ id } .jpg` ,
28- ) ;
29- result . rightAnswer = data . name ;
30- }
31- } ) ,
32- ) ,
16+ const questions = await Promise . all (
17+ questionsIdArray . map ( this . getQuestion ( ) ) ,
18+ ) ;
19+ const answers = questions . map ( ( question ) => question . name ) ;
20+ const rightAnswer = questions . find (
21+ ( question ) => rightAnswerId === question . id ,
22+ ) . name ;
23+ const questionImage = btoa (
24+ `static/assets/img/modes/${ this . mode } /${ rightAnswerId } .jpg` ,
3325 ) ;
26+ return {
27+ image : questionImage ,
28+ answers,
29+ rightAnswer,
30+ } ;
31+ }
3432
35- return result ;
33+ getQuestion ( ) {
34+ return ( questionId ) =>
35+ this . fetchData ( this . mode , questionId ) . then ( ( questionResponse ) => ( {
36+ id : questionId ,
37+ ...questionResponse ,
38+ } ) ) ;
3639 }
3740}
You can’t perform that action at this time.
0 commit comments