Skip to content

Conversation

@jasyl
Copy link

@jasyl jasyl commented Dec 30, 2020

React Tic Tac Toe

Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.

Reflection

Prompt Response
How are events / event handlers and useState connected? Events trigger event handlers that will ultimately update our state through useState
What are two ways to do "dynamic styling" with React? When should they be used? Inline styling & external CSS file. Inline styling can be used for elements that need simple, specific styling. Otherwise, it's recommended to use an external CSS file for better organization and debugging.
Much like Rails works with the HTTP request->response cycle, React works with the browser's input->output cycle. Describe React's cycle from receiving user input to outputting different page content. For example, a user will interact with the web page by clicking a button (some sort of event) which will then trigger function calls that will update the states that will render new views for the user.

CS Fundamentals Questions

Question Answer
What do you think is the BigO complexity of the method you use to compute a winner? O(1) because we're only dealing with a 9 x 9 grid, this will never change.
Consider what happens when React processes a state change from setState -- it must re-render all of the components that now have different content because of that change.
What kind of data structure are the components in, and what sort of algorithms would be appropriate for React's code to "traverse" those components?
Speculate wildly about what the Big-O time complexity of that code might be.
The data structure could be a tree and when changes made to the state. The time complexity would be O(n) because it has to traverse from parent to child.

const checkForWinner = (squares) => {
const flattenarray = [].concat(...squares);

const lines = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a clever way to work with this 2D array. Consider adding some comments so you remember how it's working. You might also consider how you could use loops to find rows and columns without flattening the array.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants