Skip to content

Instantly share code, notes, and snippets.

@thiskevinwang
Created February 6, 2019 21:48
Show Gist options
  • Save thiskevinwang/1b75d1acc7ba3ec7d0523fb3657b5568 to your computer and use it in GitHub Desktop.
Save thiskevinwang/1b75d1acc7ba3ec7d0523fb3657b5568 to your computer and use it in GitHub Desktop.
class Board extends React.Component {
renderSquare(i) {
return (
<Square
key={"square " + i}
value={this.props.squares[i]}
onClick={() => this.props.onClick(i)}
/>
);
}
renderSquares(n) {
let squares = [];
for (let i = n; i < n + 3; i++) {
squares.push(this.renderSquare(i));
}
return squares;
}
renderRows(i) {
return <div className="board-row">{this.renderSquares(i)}</div>;
}
render() {
return (
<div>
{this.renderRows(0)}
{this.renderRows(3)}
{this.renderRows(6)}
</div>
);
}
}
@SanderDeVeth
Copy link

SanderDeVeth commented Feb 5, 2020

The assignment was to have two for loops, I only see one in your solution.

I've changed renderRows() and render() to meet the requirements

renderRows(r){
      let rows = [];

      
      for (let i = 0; i < r; i++) {
        rows.push(<div className="board-row">{this.renderSquares(i*3)}</div>)
      }
      return rows;
    }

    render() {  
      return (
        <div>
          {this.renderRows(3)}
        </div>
      );
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment