viligen

11_Neighbours

May 20th, 2022 (edited)
847
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function myFunc(matrix) {
  2.  
  3.     let pairs = 0
  4.  
  5.     for (let r = 0; r < matrix.length; r++) {
  6.         for (let c = 0; c < matrix[r].length; c++) {
  7.  
  8.             if ((c + 1 < matrix[r].length) && (matrix[r][c] === matrix[r][c + 1])) { pairs++ }
  9.  
  10.  
  11.             if ((r + 1 < matrix.length) && (matrix[r][c] === matrix[r + 1][c])) { pairs++ }
  12.         }
  13.     }
  14.  
  15.  
  16.     return pairs
  17. }
  18.  
RAW Paste Data Copied