Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  let counterWin = 0;
  2.         let winIndex = null;
  3.         for (let i = 0; i < WINNING_COMBINATION.length; i++) {
  4.             counterWin = 0;
  5.             indexWin = null;
  6.             for (let index of WINNING_COMBINATION[i]) {
  7.                 if (cellElements[index].classList.contains(CIRCLE_CLASS)) {
  8.                     counterWin++;
  9.                 } else if (cellElements[index].classList.length != 2) {
  10.                     winIndex = index;
  11.                 }
  12.  
  13.                 if (counterWin == 2) {
  14.                     if (winIndex == null) {
  15.                         continue;
  16.                     }
  17.                     break;
  18.                 }
  19.             }
  20.  
  21.             if (winIndex != null && counterWin == 2) {
  22.                 break;
  23.             }
  24.         }
  25.  
  26.         return counterWin == 2 ? winIndex : null;
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement