Skip to content

Fire & Water @ Pauline Chane - Hanh Solo#20

Open
seattlefurby17 wants to merge 10 commits intoAda-C14:masterfrom
ghostfruitleaf:master
Open

Fire & Water @ Pauline Chane - Hanh Solo#20
seattlefurby17 wants to merge 10 commits intoAda-C14:masterfrom
ghostfruitleaf:master

Conversation

@seattlefurby17
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? Event listeners -onClickCallback invoke the event handler function-call back function which changes the useState.
What are two ways to do "dynamic styling" with React? When should they be used? In line and link to a style sheet.
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. The App.js is like a cookie recipe and the components are ingredients. What we see when the React app render is a batch of cookies. Every time, we swap an ingredients-change the state of a component-we still need all the new ingredients to make a fresh batch of cookies because we already used all the ingredients in the last batch. We still get cookies with either new look or new flavor.

CS Fundamentals Questions

Question Answer
What do you think is the BigO complexity of the method you use to compute a winner? We think it's O(1) because there will only be 8 wining combinations.
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.
Hash of arrays, we iterate through each component using for loops. For each component, we iterate through each element. Time complexity will be O(n^2).

Copy link

@kaidamasaki kaidamasaki left a comment

Choose a reason for hiding this comment

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

For TicTacToe we reviewed test results, the checkForWinner function, and onClickCallback function.

Good work implementing a React project using state and callback functions!

Comment on lines +61 to +70
const WINNING_INDEX = [
[[0, 0], [0, 1], [0, 2]],
[[1, 0], [1, 1], [1, 2]],
[[2, 0], [2, 1], [2, 2]],
[[0, 0], [1, 0], [2, 0]],
[[0, 1], [1, 1], [2, 1]],
[[0, 2], [1, 2], [2, 2]],
[[0, 0], [1, 1], [2, 2]],
[[0, 2], [1, 1], [2, 0]]
];

Choose a reason for hiding this comment

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

I really like your WINNING_INDEX approach, it's very elegant!

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.

2 participants