-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkWinner.js
19 lines (16 loc) · 920 Bytes
/
checkWinner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function isWinner(board , symbol){
// check for rows .
if(board[0] == board[1] && board[1] == board[2] && board[2]== symbol) return symbol;
if(board[3] == board[4] && board[4] == board[5] && board[5]== symbol) return symbol;
if(board[6] == board[7] && board[7] == board[8] && board[8]== symbol) return symbol;
// check for coloumns
if(board[0] == board[3] && board[3] == board[6] && board[6]== symbol) return symbol;
if(board[1] == board[4] && board[4] == board[7] && board[7]== symbol) return symbol;
if(board[2] == board[5] && board[5] == board[8] && board[8]== symbol) return symbol;
// diagonal check
if(board[0] == board[4] && board[4] == board[8] && board[4]== symbol) return symbol;
if(board[2] == board[4] && board[4] == board[6] && board[4]== symbol) return symbol;
//if no one win the game .
return "";
}
export default isWinner;