Advertisement
vladovip

Equal Neighbours _JS Fund_Arr Advance MoreEX

Feb 17th, 2022
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.  
  3.     let counter = 0;
  4.  
  5.     for (let index = 0; index < args.length - 1; index++) {
  6.  
  7.         for (let j = 1; j < args[index].length; j++) {
  8.  
  9.             if (args[index][j] == args[index + 1][j]) {
  10.  
  11.                 counter++;
  12.  
  13.             }
  14.  
  15.             if (args[index][j] == args[index][j - 1]) {
  16.  
  17.                 counter++;
  18.  
  19.             }
  20.  
  21.         }
  22.  
  23.     }
  24.  
  25.     for (let index = 0; index < args[args.length - 1].length; index++) {
  26.  
  27.         if (args[args.length - 1][index] == args[args.length - 1][index + 1]) {
  28.  
  29.             counter++;
  30.  
  31.         }
  32.  
  33.     }
  34.  
  35.     for (let index = 0; index < args.length - 1; index++) {
  36.  
  37.         if (args[index][0] == args[index + 1][0]) {
  38.  
  39.             counter++;
  40.  
  41.         }
  42.  
  43.     }
  44.  
  45.     console.log(counter);
  46.  
  47. }
  48. solve([['2', '3', '4', '7', '0'],
  49. ['4', '0', '5', '3', '4'],
  50. ['2', '3', '5', '4', '2'],
  51. ['9', '8', '7', '5', '4']]
  52. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement