Advertisement
Spocoman

01. Equal Neighbors

Feb 10th, 2022
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function equalNeighbors(matrix) {
  2.     let count = 0;
  3.     for (let row = 0; row < matrix.length; row++) {
  4.         for (let col = 0; col < matrix[row].length - 1; col++) {
  5.  
  6.             if (matrix[row][col] === matrix[row][col + 1]) {
  7.                 count++;
  8.             }
  9.         }
  10.     }
  11.     for (let row = 0; row < matrix.length - 1; row++) {
  12.         for (let col = 0; col < matrix[row].length; col++) {
  13.  
  14.             if (matrix[row][col] === matrix[row + 1][col]) {
  15.                 count++;
  16.             }
  17.         }
  18.     }
  19.     console.log(count);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement