if you can compromise on space (worst case O(n)), you can optimize the time complexity to O(1): maintain 4 arrays, one each for rowCount[3], columnCount[3], diagonol1Count[3], diagonol2Count[3]. For each move of player, increment the rowCount and columnCount for the indexes of the cell marked by the player. Check if the rowCount[rowIndex] or colimnCount[columnIndex] reached boardLength (here, 3).
the condition (p1 === p2 && p2 === p3 && p1 === p3) is not really necessary this one (p1 === p2 && p2 === p3) is enough as if p1 is equal to p2 and p2 is equal to p3 then p1 will be equal to p3 let's assume p1 = 'X' p2 = 'X' it is imposiible for p1 to equal p2 and p2 to equal p3 and p1 not to equal p3 also you shouldn't declare variables with let unless you plan to re-assign them, use const instead, leave let for variables meant to be re-assigned. that way your code expresses itself with only necessary semantics. If I am reading someone else's code and see a variable declared with let, it creates a bias in my mind that says "oh, this variable will be re-assigned". Follow the principle of minimum functionality necessary. let has a function, it is to allow variables to be re-assigned, when you don't need varibale re-assignment, don't use it, don't allow for that bias to be created in the code's reader's mind. one last point, look into function components and hooks, they'll help you write neater and more expressive react apps with less code. the react core team has announced that while class components will not be deprecated anytime soon, they regard function components and hooks (hooks only work inside function components) as the longer lasting future of the react api. they have become the first class citizens of the react api. just passing by and leaving my grain of salt of constructive criticism, cheers and good content 👍 p.s. don't use == use ===, as a matter of principle we should always know what types we're dealing with, we should not indulge ourselves with the soft equality operator ==
Norberto Cáceres I was thinking the same things. Plus, there was no check to see if a spot was already taken or any logic to prevent input/reset the board if the game was over.
I think the reason ur on click didn't work at first is because you didn't bind the function in the constructor so in the constructor u could have this.squareClicked = this.squareClicked.bind(this) that way you can call it in the curly braces as such => {squareClicked}
He's using Visual Code Studio and he's using JavaScript / React which work in the browser. If he would work on back end, he could use the console actually and use Python or a back end language.
Box-sizing: border-box; would've solved your problem(part where you set 31rem to your box)
i was asked to build a tic tac toe app by amazon for a front-end position. so pay attention ladies
For chess. You should include time limits for players. Also, remember there are multiple ways to end up with a draw.
Yeah please,do chess next
Sir Toad he didn’t do it yet xD
Sir Toad it is,it’s tic tac toe with 64 squares instead of 9,you just have to add figures,and allow them to move using valid moves!
00:17 helps you grow in what way? @CodeBabes
if you can compromise on space (worst case O(n)), you can optimize the time complexity to O(1): maintain 4 arrays, one each for rowCount[3], columnCount[3], diagonol1Count[3], diagonol2Count[3]. For each move of player, increment the rowCount and columnCount for the indexes of the cell marked by the player. Check if the rowCount[rowIndex] or colimnCount[columnIndex] reached boardLength (here, 3).
the condition (p1 === p2 && p2 === p3 && p1 === p3)
is not really necessary
this one (p1 === p2 && p2 === p3)
is enough as if p1 is equal to p2 and p2 is equal to p3 then p1 will be equal to p3
let's assume
p1 = 'X'
p2 = 'X'
it is imposiible for p1 to equal p2 and p2 to equal p3 and p1 not to equal p3
also you shouldn't declare variables with let unless you plan to re-assign them, use const instead, leave let for variables meant to be re-assigned.
that way your code expresses itself with only necessary semantics. If I am reading someone else's code and see a variable declared with let, it creates
a bias in my mind that says "oh, this variable will be re-assigned". Follow the principle of minimum functionality necessary. let has a function,
it is to allow variables to be re-assigned, when you don't need varibale re-assignment, don't use it, don't allow for that bias to be created in the
code's reader's mind.
one last point, look into function components and hooks, they'll help you write neater and more expressive react apps with less code. the react core team
has announced that while class components will not be deprecated anytime soon, they regard function components and hooks (hooks only work inside function components)
as the longer lasting future of the react api. they have become the first class citizens of the react api.
just passing by and leaving my grain of salt of constructive criticism,
cheers and good content 👍
p.s.
don't use == use ===, as a matter of principle we should always know what types we're dealing with, we should not indulge ourselves with the
soft equality operator ==
Norberto Cáceres
I was thinking the same things.
Plus, there was no check to see if a spot was already taken or any logic to prevent input/reset the board if the game was over.
Transitive axiom :-)
Maybe check if tile is occupied on click?
if (board[index] === '' && winningMsg === '') { ... }
Please do more pattern videos
I think the reason ur on click didn't work at first is because you didn't bind the function in the constructor so in the constructor u could have this.squareClicked = this.squareClicked.bind(this) that way you can call it in the curly braces as such => {squareClicked}
it did not work for me , i cannot see the output
Can someone provide me complete file ? i tried to recreate it and its not working.
Im new to programming. Why exactly is he programming inside the Linux VM and not windows itself?
He's using Visual Code Studio and he's using JavaScript / React which work in the browser. If he would work on back end, he could use the console actually and use Python or a back end language.
Octavian David you completely misunderstood what he was asking.
haven't seen a class component since 2017, cute
Can you check the win condition with a recursive function?
how can we write the same using A* algo??
What about draws? Clicking into a square that's already set? This is not a good technical interview...
This would have taken me a week. In fact I made a simple game for a course once and it took a few weeks. I wish I could code faster.
any new coding challenge//leet_code//codewars vid?
More of this please, great platform to learn
Hahahaha the “that was cringe” was so funny for some reason
Would love to see more small projects like that for beginners.
Class component
Ok Boomer
Make 6x6 tic tac toe
Human Vs Ai, Minimax could be implemented ...
hm, this seems very brute force like :/
Nick reminds me of Shikamaru lol
dude that thumbnail 😂😂😂😂😂
Great video. Keep this series coming. U went a little too fast for winning combos though.
I like your videos although I don't know JS😂
But you rock, I like the child in you🔥🤘
React getting started example in the docs lol
my fav youtuber!!!
Thanks so much 💜
yo I think The Coding Train stole your thumbnail style XP
its very good idea not to show to ur viewers code u wrote just make cut on ur video and show result like we all here seers
and half of screen its just view of ur useless desktop nice job man
rn ur vid has 666 likes
Thank you sir your videos help a lot please make many videos love from India ❤️❤️❤️
Nubie job pffff