Created
August 11, 2018 21:26
-
-
Save lincolndbryant/6f4daa76e7b0532f8514ee6bc91ce595 to your computer and use it in GitHub Desktop.
BoardData.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BoardData { | |
constructor(size = 8) { | |
this.size = size; | |
this.cells = Array(8).fill(null).map(() => { | |
return Array(8).fill(null); | |
}); | |
} | |
getRow(i) { | |
return this.cells[i]; | |
} | |
getCol(i) { | |
return this.cells.map(row => row[i]); | |
} | |
getCell(row, col) { | |
return this.getRow(row)[col]; | |
} | |
hasCellAt(row, col) { | |
return Boolean(this.getRow(row)[col]); | |
} | |
setCell(row, col, val) { | |
return this.getRow(row)[col] = val; | |
} | |
} | |
const b = new BoardData(); | |
b.setCell(2, 2, 'red'); | |
console.log(b.hasCellAt(2, 2)); | |
console.log(b.getCell(2, 2)); | |
console.log(b.getRow(2)); | |
console.log(b.getCol(2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment