File tree Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -19,21 +19,13 @@ function App() {
19
19
] ;
20
20
21
21
const checkWins = ( array ) => {
22
- let didWin = false ;
23
- winnings . forEach ( ( item ) => {
24
- if (
25
- item [ 0 ] === array [ 0 ] &&
26
- item [ 1 ] === array [ 1 ] &&
27
- item [ 2 ] === array [ 2 ]
28
- ) {
29
- didWin = true ;
30
- alert ( "win" ) ;
31
- }
32
- } ) ;
33
- return didWin ;
22
+ return winnings . some ( ( item ) => {
23
+ return item . every ( ( index ) => array . includes ( index ) )
24
+ } )
34
25
} ;
35
26
36
27
const handleClick = ( i ) => {
28
+ if ( xInput . includes ( i ) || oInput . includes ( i ) ) return ;
37
29
setXTurn ( ! xTurn ) ;
38
30
39
31
if ( xTurn ) {
@@ -42,13 +34,26 @@ function App() {
42
34
43
35
if ( tempX . length >= 3 ) {
44
36
let didWin = checkWins ( tempX ) ;
37
+ console . log ( 'didWin' , didWin )
38
+
39
+ if ( didWin ) {
40
+ alert ( 'win' )
41
+ setXInput ( [ ] )
42
+ setOInput ( [ ] )
43
+ }
45
44
}
46
45
} else {
47
46
let tempO = [ ...oInput , i ] ;
48
47
setOInput ( tempO ) ;
49
48
50
49
if ( tempO . length >= 3 ) {
51
50
let didWin = checkWins ( tempO ) ;
51
+ console . log ( 'didWin' , didWin )
52
+ if ( didWin ) {
53
+ alert ( 'win' )
54
+ setXInput ( [ ] )
55
+ setOInput ( [ ] )
56
+ }
52
57
}
53
58
}
54
59
} ;
You can’t perform that action at this time.
0 commit comments