Skip to content

Instantly share code, notes, and snippets.

@lincolndbryant
Created August 11, 2018 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lincolndbryant/6f4daa76e7b0532f8514ee6bc91ce595 to your computer and use it in GitHub Desktop.
Save lincolndbryant/6f4daa76e7b0532f8514ee6bc91ce595 to your computer and use it in GitHub Desktop.
BoardData.js
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