Advertisement
viligen

equalPairs

May 20th, 2022
875
0
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.             if (c + 1 < matrix[r].length) {
  8.                 if (matrix[r][c] === matrix[r][c + 1]) { pairs++ }
  9.             }
  10.             if (r + 1 < matrix.length) {
  11.                 if (matrix[r][c] === matrix[r + 1][c]) { pairs++ }
  12.             }
  13.         }
  14.  
  15.  
  16.     }
  17.  
  18.  
  19.     return pairs
  20. }
  21.  
  22.  
  23.  
  24. console.log(myFunc([['test', 'yes', 'yo', 'ho'],
  25. ['well', 'done', 'yo', '6'],
  26. ['not', 'done', 'yet', '5']]
  27. ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement