Advertisement
braveheart1989

02. X-Removal

Oct 15th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let matrix = input.map(row => row.toLowerCase().split(""));
  3.     let resultMatrix = input.map(row => row.split(""));
  4.  
  5.     for (let row = 0; row < matrix.length - 2; row++) {
  6.         for (let col = 0; col < matrix[row].length - 2; col++) {
  7.             let el = matrix[row][col];
  8.             if (el == matrix[row][col + 2] &&
  9.                 el == matrix[row + 1][col + 1] &&
  10.                 el == matrix[row + 2][col] &&
  11.                 el == matrix[row + 2][col + 2]) {
  12.  
  13.                 resultMatrix[row][col]="";
  14.                 resultMatrix[row][col + 2]="";
  15.                 resultMatrix[row + 1][col + 1]="";
  16.                 resultMatrix[row + 2][col]="";
  17.                 resultMatrix[row + 2][col + 2]="";
  18.             }
  19.         }
  20.     }
  21.     for (let r of resultMatrix) {
  22.         console.log(r.join(""));
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement