Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // liczenie zywych sąsiadów
  2. function countLiveNeighbors(row, col) {
  3.     let count = 0;
  4.     for(let i = row - 1; i <= row + 1; i++) {
  5.         if (i >= 0 && i < rows){
  6.             for(let j = col - 1; j <= col + 1; j++) {
  7.                 if (j >= 0 && j < columns){
  8.                     if (i != row || j != col) {
  9.                         count += grid[i][j].classList.contains("alive") ? 1 : 0;                        
  10.                     }                    
  11.                 }                
  12.             }            
  13.         }            
  14.     }
  15.     return count;
  16. }