Skip to content

Denise & Li - Soil Classroom#8

Open
nerdyistrendy wants to merge 18 commits intoAda-C14:masterfrom
nerdyistrendy:master
Open

Denise & Li - Soil Classroom#8
nerdyistrendy wants to merge 18 commits intoAda-C14:masterfrom
nerdyistrendy:master

Conversation

@nerdyistrendy
Copy link

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? UseState get the actions from the user and update the state. Event handlers listen to user's actions to determine what will be done.
What are two ways to do "dynamic styling" with React? When should they be used? Inline styling and create a separate css file. We prefer to use separate css files.
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. Event listen will get the user input and react will update the value/state and output it.

CS Fundamentals Questions

Question Answer
What do you think is the BigO complexity of the method you use to compute a winner? Because our matrix size is fixed and number of possibilities are fixed, so our output will not scale. So we have a constant BigO complexity.
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.
It might work like a hash map, where we will have a unique key for each object and then we use O(1) lookup time to find the key and update the value.

// 3. Go across each diagonal to see if
// all three squares have the same value.

const winPossibilities = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]

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 store the winning combinations. You could also consider how you could write loops to check for 3 across in rows and columns in the 2D 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