SHARE
TWEET

Untitled

a guest Oct 15th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Spaces {
  2.     constructor(r, c) {
  3.         this.r = r;
  4.         this.c = c;
  5.         this.len = 1;
  6.         this.direction = "right";
  7.         this.used = false;
  8.     }
  9. }
  10.  
  11.  
  12. let findSpaces = (grid, minLength) => {
  13.  
  14.     let spaceList = [];
  15.     let gLen = 10;
  16.  
  17.     // Horizantal scan
  18.     for (let i = 0; i < gLen; i++) {
  19.         for (let j = 0; j < gLen; j++) {
  20.             let c = grid[i][j];
  21.             if (c === '-') {
  22.                 let s = new Spaces(i, j);
  23.                 while (grid[i][++j] === '-') s.len++;
  24.  
  25.                 if (s.len >= minLength) {
  26.                     spaceList.push(s)
  27.                 }
  28.             }
  29.  
  30.         }
  31.     }
  32.  
  33.     //vertical scan
  34.     for (let i = 0; i < gLen; i++) {
  35.         for (let j = 0; j < gLen; j++) {
  36.             let c = grid[j][i];
  37.             if (c === '-') {
  38.                 let s = new Spaces(j, i);
  39.                 s.direction = "down";
  40.                 while (++j < gLen && grid[j][i] === '-') s.len++;
  41.  
  42.                 if (s.len >= minLength) {
  43.                     spaceList.push(s)
  44.                 }
  45.             }
  46.  
  47.         }
  48.     }
  49.     return spaceList;
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top