-
Notifications
You must be signed in to change notification settings - Fork 0
Checkpoint1 towers #7
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
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 logic here, but a couple things need work. When you check for something like if (array.pop()) you are changing the array, but not saving what is popped. Also, the isLegal() function should have been checked in the if statement to determine if the movePiece() function should have been called. Pretty clean syntax, just some notes here and there.
| // Your code here | ||
| // movePiece should use array method and dot method to select last index and grab it through push and pop | ||
| const movePiece = (startStack, endStack) => { | ||
| stacks[endStack].push(stacks[startStack].pop()); |
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.
Very concise!
|
|
||
| // Hierarchy of logic, if the stack has nothing in it, legal move, else the starting index popped should be less then the pop of the end stack. Or else move will not work. | ||
| const isLegal = (startStack, endStack) => { | ||
| if (stacks[endStack].length === 0) { |
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.
What happens if the startStack is empty?
| const isLegal = (startStack, endStack) => { | ||
| if (stacks[endStack].length === 0) { | ||
| return true; | ||
| } else if (stacks[startStack].pop() < stacks[endStack].pop()) { |
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.
.pop() changes the array, we just want to check the value of the last item in the stack if there is one ( array[array.length - 1] ).
| // use previous functions to put game together | ||
| // if move function is valid run call back legal function, if nothing else run win function. | ||
| const towersOfHanoi = (startStack, endStack) => { | ||
| if (movePiece(startStack, endStack)) { |
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.
movePiece() doesn't check anything, it moves pieces. Here, you're moving the pieces, and since movePiece will return undefines, isLegal won't even run.
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