@@ -11,49 +11,49 @@ const memoria = (previousSteps, currentStep) => {
1111 if ( currentStep . length !== 5 ) {
1212 throw 'CURRENT_STEP_INCOMPLETED'
1313 }
14- let answer
15- switch ( previousSteps . length ) {
16- case 0 :
17- switch ( currentStep [ 0 ] ) {
18- case 1 : answer = currentStep [ 2 ] ; break ;
19- case 2 : answer = currentStep [ 2 ] ; break ;
20- case 3 : answer = currentStep [ 3 ] ; break ;
21- case 4 : answer = currentStep [ 4 ] ; break ;
22- }
23- break ;
24- case 1 :
25- switch ( currentStep [ 0 ] ) {
26- case 1 : answer = 4 ; break ;
27- case 2 : answer = currentStep [ previousSteps [ 0 ] . indexOf ( previousSteps [ 0 ] [ 5 ] , 1 ) ] ; break ;
28- case 3 : answer = currentStep [ 1 ] ; break ;
29- case 4 : answer = currentStep [ previousSteps [ 0 ] . indexOf ( previousSteps [ 0 ] [ 5 ] , 1 ) ] ; break ;
30- }
31- break
32- case 2 :
33- switch ( currentStep [ 0 ] ) {
34- case 1 : answer = previousSteps [ 1 ] [ 5 ] ; break ;
35- case 2 : answer = previousSteps [ 0 ] [ 5 ] ; break ;
36- case 3 : answer = currentStep [ 3 ] ; break ;
37- case 4 : answer = 4 ; break ;
38- }
39- break
40- case 3 :
41- switch ( currentStep [ 0 ] ) {
42- case 1 : answer = currentStep [ previousSteps [ 0 ] . indexOf ( previousSteps [ 0 ] [ 5 ] , 1 ) ] ; break ;
43- case 2 : answer = currentStep [ 1 ] ; break ;
44- case 3 : answer = currentStep [ previousSteps [ 1 ] . indexOf ( previousSteps [ 1 ] [ 5 ] , 1 ) ] ; break ;
45- case 4 : answer = currentStep [ previousSteps [ 1 ] . indexOf ( previousSteps [ 1 ] [ 5 ] , 1 ) ] ; break ;
46- }
47- break
48- case 4 :
49- switch ( currentStep [ 0 ] ) {
50- case 1 : answer = previousSteps [ 0 ] [ 5 ] ; break ;
51- case 2 : answer = previousSteps [ 1 ] [ 5 ] ; break ;
52- case 3 : answer = previousSteps [ 3 ] [ 5 ] ; break ;
53- case 4 : answer = previousSteps [ 2 ] [ 5 ] ; break ;
54- }
55- break
56- }
14+
15+ const previousStepsTemp = Array ( 5 ) . fill ( 0 ) . map ( x => Array ( 6 ) . fill ( 0 ) )
16+ previousSteps . map ( ( step , indexStep ) => {
17+ step . map ( ( data , indexData ) => {
18+ previousStepsTemp [ indexStep ] [ indexData ] = data
19+ } )
20+ } )
21+
22+ const rules = [
23+ {
24+ 1 : currentStep [ 2 ] ,
25+ 2 : currentStep [ 2 ] ,
26+ 3 : currentStep [ 3 ] ,
27+ 4 : currentStep [ 4 ]
28+ } ,
29+ {
30+ 1 : 4 ,
31+ 2 : currentStep [ previousStepsTemp [ 0 ] . indexOf ( previousStepsTemp [ 0 ] [ 5 ] , 1 ) ] ,
32+ 3 : currentStep [ 1 ] ,
33+ 4 : currentStep [ previousStepsTemp [ 0 ] . indexOf ( previousStepsTemp [ 0 ] [ 5 ] , 1 ) ]
34+ } ,
35+ {
36+ 1 : previousStepsTemp [ 1 ] [ 5 ] ,
37+ 2 : previousStepsTemp [ 0 ] [ 5 ] ,
38+ 3 : currentStep [ 3 ] ,
39+ 4 : 4
40+ } ,
41+ {
42+ 1 : currentStep [ previousStepsTemp [ 0 ] . indexOf ( previousStepsTemp [ 0 ] [ 5 ] , 1 ) ] ,
43+ 2 : currentStep [ 1 ] ,
44+ 3 : currentStep [ previousStepsTemp [ 1 ] . indexOf ( previousStepsTemp [ 1 ] [ 5 ] , 1 ) ] ,
45+ 4 : currentStep [ previousStepsTemp [ 1 ] . indexOf ( previousStepsTemp [ 1 ] [ 5 ] , 1 ) ]
46+ } ,
47+ {
48+ 1 : previousStepsTemp [ 0 ] [ 5 ] ,
49+ 2 : previousStepsTemp [ 1 ] [ 5 ] ,
50+ 3 : previousStepsTemp [ 3 ] [ 5 ] ,
51+ 4 : previousStepsTemp [ 2 ] [ 5 ]
52+ } ,
53+ ]
54+
55+ const answer = rules [ previousSteps . length ] [ currentStep [ 0 ] ]
56+
5757 currentStep . push ( answer )
5858 previousSteps . push ( currentStep )
5959 return previousSteps
0 commit comments