Advertisement
fbinnzhivko

Untitled

Oct 4th, 2016
1,462
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(' '));
  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 (row == matrix.length - 2 && matrix[row + 1][col] == matrix[row + 1][col + 1]) {
  15.                 neighbors++;
  16.             }
  17.         }
  18.     }
  19.     console.log(neighbors);
  20. }
  21. aza(['test', 'yes', 'yo', 'ho', 'well', 'done', 'yo', '6', 'not', 'done', 'yet', '5']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement