Skip to content

🌎 Schanen & 🌊 Kim#2

Open
kimvitug05 wants to merge 9 commits intoAda-C14:masterfrom
kimvitug05:master
Open

🌎 Schanen & 🌊 Kim#2
kimvitug05 wants to merge 9 commits intoAda-C14:masterfrom
kimvitug05:master

Conversation

@kimvitug05
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 is changed based on an event that is defined by the event handler.
What are two ways to do "dynamic styling" with React? When should they be used? The two ways to do dynamic styling are 1.) inline with the style attribute and 2.) external stylesheets & the className attribute. Inline styling is discouraged. Ternary statements with different classNames/different CSS can allow for dynamic styling.
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. If an event handler exists, then it's constantly listening for an event to happen. If the event happens, then it creates a state change and renders those changes in the browser.

CS Fundamentals Questions

Question Answer
What do you think is the BigO complexity of the method you use to compute a winner? The BigO complexity is O(1) because we iterate through strikes which is an array of fixed length.
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.
Components are structured like a virtual DOM. They are tree shaped. One algorithm that would be appropriate would be Tree Traversal. Each node in the tree is visited once and there are 'n' nodes in the tree so the time complexity is O(n).

Copy link

@CheezItMan CheezItMan 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 and they do everything required.

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

Comment on lines +68 to +84
const strikes = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6],
];
for (let i = 0; i < strikes.length; i++) {
const [a, b, c] = strikes[i];
if (squaresArray[a].value && squaresArray[a].value === squaresArray[b].value && squaresArray[a].value === squaresArray[c].value) {
setWinner(squaresArray[a].value);
return true;
}
}

Choose a reason for hiding this comment

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

This is quite clever!

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