File tree Expand file tree Collapse file tree
packages/drag-in-the-blank Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -201,7 +201,9 @@ export class Choices extends React.Component {
201201 }
202202
203203 // if duplicates not allowed, remove the choices that are used to define the correct response
204- return choices . filter ( ( choice ) => ! Object . values ( correctResponse ) . includes ( choice . id ) ) ;
204+ return choices . filter (
205+ ( choice ) => ! ( correctResponse && Object . values ( correctResponse ) . includes ( choice . id ) )
206+ ) ;
205207 } ;
206208
207209 render ( ) {
Original file line number Diff line number Diff line change 11import cloneDeep from 'lodash/cloneDeep' ;
2+ import reduce from 'lodash/reduce' ;
23
34const replaceHtmlRegex = / < (? ! i m g ) [ ^ > ] * > ? / gm;
45
5- export const getAllCorrectResponses = ( { correctResponse = { } , alternateResponses = { } } ) =>
6- Object . entries ( correctResponse ) . reduce (
7- ( acc , [ key , val ] ) => {
8- acc . possibleResponses [ key ] = [ val , ...( alternateResponses [ key ] ? cloneDeep ( alternateResponses [ key ] ) : [ ] ) ] ;
6+ export const getAllCorrectResponses = ( { correctResponse, alternateResponses } ) => {
7+ return reduce (
8+ correctResponse || { } ,
9+ ( obj , val , key ) => {
10+ obj . possibleResponses [ key ] = [ val ] ;
911
10- const length = acc . possibleResponses [ key ] . length ;
11- acc . numberOfPossibleResponses = acc . numberOfPossibleResponses === undefined
12- ? length
13- : Math . min ( acc . numberOfPossibleResponses , length ) ;
12+ if ( alternateResponses && alternateResponses [ key ] ) {
13+ obj . possibleResponses [ key ] = [ ...obj . possibleResponses [ key ] , ...cloneDeep ( alternateResponses [ key ] ) ] ;
14+ }
1415
15- return acc ;
16+ if (
17+ obj . numberOfPossibleResponses === undefined ||
18+ obj . numberOfPossibleResponses > obj . possibleResponses [ key ] . length
19+ ) {
20+ obj . numberOfPossibleResponses = obj . possibleResponses [ key ] . length ;
21+ }
22+
23+ return obj ;
1624 } ,
1725 {
1826 possibleResponses : { } ,
1927 numberOfPossibleResponses : undefined ,
2028 } ,
2129 ) ;
30+ } ;
2231
2332export const choiceIsEmpty = ( choice ) => {
2433 if ( choice ) {
You can’t perform that action at this time.
0 commit comments