-
Notifications
You must be signed in to change notification settings - Fork 0
Initial commit of Towers of Hanoi code #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gh-pages
Are you sure you want to change the base?
Conversation
| function verticalWin() { | ||
| // if vertical grid has equal items, there is a win | ||
|
|
||
| return [board[0][0], board[1][0], board[2][0]].every(square => square === playerTurn) || [board[0][1], board[1][1], board[2][1]].every(square => square === playerTurn) || [board[0][2], board[1][2], board[2][2]].every(square => square === playerTurn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of the every() js method here.
|
|
||
| function checkForWin() { | ||
| // | ||
| if (horizontalWin()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consolidate your checkForWin() logic with || operators to reduce redundant code.
|
|
||
| const validValue = (myIndex) => { | ||
| const valuesArr = [0,1,2]; | ||
| return valuesArr.some(validIndex => myIndex == validIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good data scrub.
| board[row][column] = playerTurn; | ||
|
|
||
| if (!checkForWin()) { | ||
| if (playerTurn === 'X') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a ternary operator to toggle the playerTurn value.
Checkpoint Rubric
This is the rubric that your instructor will use to grade your checkpoints. Please do not edit.
Checkpoint 1
Checkpoint 2
Checkpoint 3