Untitled

 avatar
unknown
typescript
2 years ago
531 B
5
Indexable
// Object-Oriented
export class Board<T> {
  // Other properties...

  private _board: T[][];

  constructor(gen: Generator<T>, width: number, height: number) {
    // Other initialization...
    this._board = this.buildBoard(gen, width, height);
  }

  // Other methods...

  private buildBoard(gen: Generator<T>, w: number, h: number): T[][] {
    const board = [];
    for (let i = 0; i < h; i++) {
      const row = [...Array(w)].map(i => gen.next());
      board.push(row);
    }
    return board;
  }
}
Editor is loading...
Leave a Comment