Advertisement
fbinnzhivko

Untitled

Sep 30th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function aza(input) {
  2.  
  3.     let neighbors = 0;
  4.     let matrix = input.map(row=>row.split(' ').map(Number));
  5.  
  6.     for (let row = 0; row < matrix.length - 1; row++)
  7.         for (let col = 0; col < matrix[row].length; col++) {
  8.             if (matrix[row][col] == matrix[row + 1][col]) {
  9.                 neighbors++;
  10.             }
  11.             if (matrix[row][col] == matrix[row][col + 1]) {
  12.                 neighbors++;
  13.             }
  14.             // if (matrix[row][col] == matrix[row + 1][col + 1]) {
  15.             //     neighbors++;
  16.             // }
  17.         }
  18.     console.log(neighbors);
  19. }
  20. //aza(['2 3 4 7 0', '4 0 5 3 4','2 3 5 4 2', '9 8 7 5 4']);
  21. aza(['2 2 5 7 4', '4 0 5 3 4', '2 5 5 4 2']);
  22. aza(['test', 'yes', 'yo', 'ho', 'well', 'done', 'yo', '6', 'not', 'done', 'yet', '5']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement