Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Spaces {
- constructor(r, c) {
- this.r = r;
- this.c = c;
- this.len = 1;
- this.direction = "right";
- this.used = false;
- }
- }
- let findSpaces = (grid, minLength) => {
- let spaceList = [];
- let gLen = 10;
- // Horizantal scan
- for (let i = 0; i < gLen; i++) {
- for (let j = 0; j < gLen; j++) {
- let c = grid[i][j];
- if (c === '-') {
- let s = new Spaces(i, j);
- while (grid[i][++j] === '-') s.len++;
- if (s.len >= minLength) {
- spaceList.push(s)
- }
- }
- }
- }
- //vertical scan
- for (let i = 0; i < gLen; i++) {
- for (let j = 0; j < gLen; j++) {
- let c = grid[j][i];
- if (c === '-') {
- let s = new Spaces(j, i);
- s.direction = "down";
- while (++j < gLen && grid[j][i] === '-') s.len++;
- if (s.len >= minLength) {
- spaceList.push(s)
- }
- }
- }
- }
- return spaceList;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement