Advertisement
DNNdrago

02. Reveal Triangles

Jul 30th, 2014
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (input) {
  2.  
  3.     var result = input.slice(0);
  4.  
  5.     for (var i = input.length - 1; i >= 1; i -= 1) {
  6.         for (var j = 0; j < input[i].length - 2; j += 1) {
  7.             if (input[i][j] === input[i][j+1] && input[i][j] === input[i][j+2]) {
  8.                 if(input[i][j] === input[i-1][j+1]) {
  9.                     result[i] = result[i].substr(0, j) + '***' + result[i].substr(j+3);
  10.                     result[i-1] = result[i-1].substr(0, j+1) + '*' + result[i-1].substr(j+2);
  11.                 }
  12.             }
  13.         }
  14.     }
  15.  
  16.  
  17.     for(var str in result) {
  18.         console.log(result[str]);
  19.     }
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement